Learn R Programming

terra (version 0.5-2)

collapse: Collapse cell values from a multi-layer SpatRaster

Description

Use a single layer SpatRaster object to select cell values from different layers in a multi-layer SpatRaster and "collapse" it into a single layer. 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 extract for extraction of values by cell, point, or otherwise.

Usage

# S4 method for SpatRaster
collapse(x, y, filename="", overwrite=FALSE, wopt=list(), ...)

Arguments

x

SpatRaster

y

SpatRaster

filename

character. Output filename. Optional

overwrite

logical. If TRUE, filename is overwritten

wopt

list. Options for writing files as in writeRaster

...

additional arguments. None implemented

Value

SpatRaster

See Also

tapp, extract

Examples

Run this code
# NOT RUN {
r <- rast(ncol=10, nrow=10)
values(r) <- 1
s <- c(r, r+2, r+5)
set.seed(1)
values(r) <- round((runif(ncell(r)))*3)
x <- collapse(s, r)
# }

Run the code above in your browser using DataLab