subset: Subset layers in a Raster* object

Description Usage Arguments Value See Also Examples

Description

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

Usage

1
2
3
4
5
## S4 method for signature 'Raster'
subset(x, subset, drop=TRUE, filename='', ...)

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

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

Value

Raster* object

See Also

dropLayer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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)

Example output

Loading required package: sp
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files
[1] 3
[1] 2
[1] "RasterLayer"
attr(,"package")
[1] "raster"
[1] "RasterStack"
attr(,"package")
[1] "raster"

raster documentation built on June 18, 2021, 9:08 a.m.