[GIS] Extracting a large layer from NetCDF using R

netcdfr

i am trying to extract specific data from an .nc file

my nc file has the following variables
hur-relative humidity
lat-latitudes
lon-longitudes
time-time
plev-pressure levels

so i want to get the data of relative humidity for a specific plev and specific time

library(ncdf)
ncin<-open.ncdf("akhil.nc")
hur.array<-get.var.ncdf(ncin,"hur")
 error: cannot allocate 2.1 gb vector

as you can see the hur is to big so is there any way to directly specify the plev values and time values directly into the
get.var.ncdf() function so has to reduce the vector size

i am new to ncdf files

Best Answer

You can use functions in the raster package to avoid this problem

library(raster)
b <- brick("akhil.nc", var="hur")
b