[raster] formal way of addressing specific layer in RasterStack?
Just curious if this is the most optimal way of addressing a specific layer in a RasterStack: -RasterStack with 14 layers called "stack" -polygon layer called "sites" # extract cell values from layer 2 of "stack" RasterStack using "sites" polygon extract_stack_sites<-extract(stack at layers[[2]], sites)) # extract summary stats (mean) for each polygon extract_stack_sites_mean<-unlist(lapply(extract_stack_sites, function(x) if (!is.null(x)) mean(x, na.rm=TRUE) else NA )) The above works, but perhaps there's a more elegant solution, especially if dealing with a range, or subset of layers within a RasterStack? Cheers -- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/raster-formal-way-of-addressing-specific-layer-in-RasterStack-tp7581866.html Sent from the R-sig-geo mailing list archive at Nabble.com.