I want to read a specific layer from a multilayer raster (format ncdf) using terra package. I want to extract each layer by polygon using terra package (it is a very fast way to extract values). I know there are other packages to open my multilayer raster but I don't want to use them. I want to use terra package but with multilayers I have many errors.
So, I tried:
r <- terra::rast(r1,nlyrs=nlyr(4))## I have a error :unable to find an inherited method #for function ‘nlyr’ for signature ‘"numeric"’
I tried :
r <- terra::rast(r1, 1) ## no error
but when I want to extract values from raster. I have this :
uat$ex <- terra::extract(r,vect(uat), fun = mean, na.rm =T)[,2]
###
error: [extract] raster has no value
r1
a character string with a netCDF file name here? Its not clear.