terra (version 0.6-9)

app: Apply a function to the cells of a SpatRaster

Description

Apply a function to values of each cell of a SpatRaster. This is similar to apply -- think of each layer in a SpatRaster as a column (or row) in a matrix

Usage

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

Arguments

x

SpatRaster object

fun

function

...

additional arguments for 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

overlay, math

Examples

Run this code
# NOT RUN {
r <- rast(ncols=10, nrows=10)
values(r) <- 1:ncell(r)
x <- c(r, r, r)
s <- app(x, fun=sum)
# }

Run the code above in your browser using DataLab