Learn R Programming

terra (version 1.9-11)

sapp: Apply a terra function that takes only a single layer and returns a SpatRaster to all layers of a SpatRaster

Description

Apply to all layers of a SpatRaster a function that only takes a single layer SpatRaster and returns a SpatRaster (these are rare). In most cases you can also use lapply or sapply for this.

Or apply the same method to each sub-dataset (SpatRaster) in a SpatRasterDataset

Usage

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

# S4 method for SpatRasterDataset sapp(x, fun, ..., filename="", overwrite=FALSE, wopt=list())

Arguments

Value

SpatRaster

See Also

lapp, app, tapp, lapply

Examples

Run this code
s <- rast(system.file("ex/logo.tif", package="terra")) + 1  

#SpatRasterDataset
sd <- sds(s*2, s/2)
y <- sapp(sd, mean)
z <- sapp(sd, function(i) 2 * mean(i))

Run the code above in your browser using DataLab