Learn R Programming

raster (version 3.6-30)

subset: Subset layers in a Raster* object

Description

Extract a set of layers from a RasterStack or RasterBrick object.

Usage

# S4 method for Raster
subset(x, subset, drop=TRUE, filename='', ...)

# S4 method for RasterStack subset(x, subset, drop=TRUE, filename='', ...)

Value

Raster* object

Arguments

x

RasterBrick or RasterStack object

subset

integer or character. Should indicate the layers (represented as integer or by their name)

drop

If TRUE, a selection of a single layer will be returned as a RasterLayer

filename

character. Output filename (optional)

...

additional arguments as for writeRaster

See Also

Examples

Run this code
s <- stack(system.file("external/rlogo.grd", package="raster"))
sel <- subset(s, 2:3)

# Note that this is equivalent to
sel2 <- s[[2:3]]


# and in this particular case:
sel3 <- dropLayer(s, 1)

nlayers(s)
nlayers(sel)

# effect of 'drop=FALSE' when selecting a single layer
sel <- subset(s, 2)
class(sel)
sel <- subset(s, 2, drop=FALSE)
class(sel)

Run the code above in your browser using DataLab