terra (version 1.0-10)

rapp: Apply a function to a range of the layers of a SpatRaster

Description

Apply a function to a range of the layers of a SpatRaster. The range is specified for each cell seperately by a two-layer SpatRaster index.

The function used should return a single value.

See app or Summary-methods if you want to apply a function to all layers (or a subset of all layers) in a SpatRaster.

Usage

# S4 method for SpatRaster
rapp(x, index, fun, ..., filename="", overwrite=FALSE, wopt=list())

Arguments

x

SpatRaster

index

factor or numeric (integer). Vector of length nlyr(x) (shorter vectors are recycled) grouping the input layers

fun

function to be applied

...

additional arguments passed to fun

filename

character. Output filename. Optional

overwrite

logical. If TRUE, filename is overwritten

wopt

list. Options for writing files as in writeRaster

Value

SpatRaster

See Also

app, Summary-methods, lapp, tapp

Examples

Run this code
# NOT RUN {
r <- rast(ncol=9, nrow=9)
values(r) <- 1:ncell(r)
s <- c(r, r, r, r, r, r)
s <- s * 1:6

start <- end <- rast(r)
start[] <- 1:3
end[]   <- 4:6
index   <- c(start, end)

rapp(s, index, fun="mean")
# }

Run the code above in your browser using DataLab