
Last chance! 50% off unlimited learning
Sale ends in
indices
.
The function used should return a single value, and the number of layers in the output Raster* equals the number of unique values in indices
.
For example, if you have a RasterStack with 6 layers, you can use indices=c(1,1,1,2,2,2)
and fun=sum
. This will return a RasterBrick with two layers. The first layer is the sum of the first three layers in the input RasterStack, and the second layer is the sum of the last three layers in the input RasterStack. See calc
if you want to use a function that returns multiple layers based on _all_ layers in the Raster* object.stackApply(x, indices, fun, filename='', na.rm=TRUE, ...)
nlayers(x)
containing all integer values between 1 and the number of layers of the output Raster*mean
or min
, and that takes an 'na.rm' argumentTRUE
, NA
cells are removed from calculationswriteRaster
calc, stackSelect
r <- raster(ncol=10, nrow=10)
r[]=1:ncell(r)
s <- brick(r,r,r,r,r,r)
s <- s * 1:6
b1 <- stackApply(s, indices=c(1,1,1,2,2,2), fun=sum)
b1
b2 <- stackApply(s, indices=c(1,2,3,1,2,3), fun=sum)
b2
Run the code above in your browser using DataLab