Get the number of layers in a Raster* object, typically used with a (multilayer) RasterStack or RasterBrick object

nlayers(x)

Arguments

x

Raster* object

Value

integer

See also

Examples

r <- raster(ncols=10, nrows=10)
values(r) <- 1:ncell(r)
s <- stack(r, r, r)
nlayers(s)
#> [1] 3
s <- stack(s,s)
nlayers(s)
#> [1] 6
s <- dropLayer(s, 2:3)
nlayers(s)
#> [1] 4