Use a single layer SpatRaster object to select cell values from different layers in a multi-layer SpatRaster. The values of the SpatRaster to select layers (y
) should be between 1
and nlyr(x)
(values outside this range are ignored); they are also truncated to integers.
See rapp
for applying af function to a range of variable size.
See extract
for extraction of values by cell, point, or otherwise.
# S4 method for SpatRaster
selectRange(x, y, z=1, filename="", overwrite=FALSE, wopt=list(), ...)
SpatRaster
SpatRaster. Cell values must be positive integers. They indicate the first layer to select for each cell
positive integer. The number of layers to select
character. Output filename. Optional
logical. If TRUE
, filename
is overwritten
list. Options for writing files as in writeRaster
additional arguments. None implemented
SpatRaster
# NOT RUN {
r <- rast(ncol=10, nrow=10)
values(r) <- 1
s <- c(r, r+2, r+5)
s <- c(s, s)
set.seed(1)
values(r) <- sample(3, ncell(r), replace=TRUE)
x <- selectRange(s, r)
x <- selectRange(s, r, 3)
# }
Run the code above in your browser using DataLab