I wrote a function to extract values from ncdf files, as shown below:
precresults <- function(x){
library(magrittr)
library(ncdf4)
library(raster)
library(ncdf.tools)
##library(ncf)
re1 <- brick(nl1a[x])
re <- extract(re1,zuobiao)
####zuobiao stands for the coordinate of the targeted sites
###extract(zuobiao)
return(re)
}
###precresults(20)
precresults11 <- lapply(1:420, precresults)
"lapply" function is used to extract values for multiple site.
However, an error occurs:
Error in UseMethod("extract_") : no applicable method for 'extract_' applied to an object of class "c('RasterBrick', 'Raster', 'RasterStackBrick', 'BasicRaster')"
How can we solve such error?