Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

stackSelect

Select cell values from a multi-layer Raster* object


Description

Use a Raster* object to select cell values from different layers in a multi-layer Raster* object. The object to select values y should have values between 1 and nlayers(x). The values of y are rounded.

See extract for extraction of values by cell, point, or otherwise.

Usage

## S4 method for signature 'RasterStackBrick,Raster'
stackSelect(x, y, recycle=FALSE, type='index', filename='', ...)

Arguments

x

RasterStack or RasterBrick object

y

Raster* object

recycle

Logical. Recursively select values (default = FALSE. Only relevant if y has multiple layers. E.g. if x has 12 layers, and y has 4 layers, the indices of the y layers are used three times.

type

Character. Only relevant when recycle=TRUE. Can be 'index' or 'truefalse'. If it is 'index', the cell values of y should represent layer numbers. If it is 'truefalse' layer numbers are indicated by 0 (not used, NA returned) and 1 (used)

filename

Character. Output filename (optional)

...

Additional arguments as for writeRaster

Value

Raster* object

See Also

Examples

r <- raster(ncol=10, nrow=10, vals=1)
s <- stack(r, r+2, r+5)
values(r) <- round((runif(ncell(r)))*3)
x <- stackSelect(s, r)

raster

Geographic Data Analysis and Modeling

v3.4-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Jacob van Etten [ctb], Michael Sumner [ctb], Joe Cheng [ctb], Dan Baston [ctb], Andrew Bevan [ctb], Roger Bivand [ctb], Lorenzo Busetto [ctb], Mort Canty [ctb], Ben Fasoli [ctb], David Forrest [ctb], Aniruddha Ghosh [ctb], Duncan Golicher [ctb], Josh Gray [ctb], Jonathan A. Greenberg [ctb], Paul Hiemstra [ctb], Kassel Hingee [ctb], Institute for Mathematics Applied Geosciences [cph], Charles Karney [ctb], Matteo Mattiuzzi [ctb], Steven Mosher [ctb], Babak Naimi [ctb], Jakub Nowosad [ctb], Edzer Pebesma [ctb], Oscar Perpinan Lamigueiro [ctb], Etienne B. Racine [ctb], Barry Rowlingson [ctb], Ashton Shortridge [ctb], Bill Venables [ctb], Rafael Wueest [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.