Search code examples
rnetcdf

how to extract precipitation data from netcdf file in R?


I am trying to extract precipitation data from a netcdf file downloaded from the cordex climate model. I applied the following codes:

library(ncdf4)    
v1 <- nc_open('pr_EUR-44_ICHEC-EC-EARTH_rcp45_r12i1p1_SMHI-RCA4_v1_day_20960101-21001231.nc')
data_v1<-ncvar_get(v1,attributes(v1$var)$names[3]) 

I got this data:

enter image description here

Here, my need is to get the data with row number 1826.

I uploaded the 20 mb size nc file here:

https://easyupload.io/ch55ic


Solution

  • The array consists of 1826 matrices, each with 106 rows and 103 columns.

    data_v1[,,1826]
    

    Should extract the matrix you're after. Please refer to Grouping functions (tapply, by, aggregate) and the *apply family, for a concise overview of some useful functions for handling arrays.