addLayer.Rd
Add a layer to a Raster* object or drop a layer from a RasterStack or RasterBrick. The object returned is always a RasterStack (unless nothing to add or drop was provided, in which case the original object is returned).
addLayer(x, ...)
dropLayer(x, i, ...)
RasterStack
file <- system.file("external/test.grd", package="raster")
s <- stack(file, file, file)
r <- raster(file)
s <- addLayer(s, r/2, r*2)
s
#> class : RasterStack
#> dimensions : 115, 80, 9200, 5 (nrow, ncol, ncell, nlayers)
#> resolution : 40, 40 (x, y)
#> extent : 178400, 181600, 329400, 334000 (xmin, xmax, ymin, ymax)
#> crs : +proj=sterea +lat_0=52.1561605555556 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +datum=WGS84 +units=m +no_defs
#> names : test.1.1, test.2.1, test.3, test.1.2, test.2.2
#> min values : 138.70707, 138.70707, 138.70707, 69.35354, 277.41415
#> max values : 1736.058, 1736.058, 1736.058, 868.029, 3472.116
#>
s <- dropLayer(s, c(3, 5))
nlayers(s)
#> [1] 3