Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

calc-RasterArray-function-method

Calculate method for the RasterArray object


Description

Calculate values for a new RasterLayer/RasterArray object from another RasterArray object, using a formula.

Usage

## S4 method for signature 'RasterArray,'function''
calc(x, fun, margin = NULL, na.rm = NULL, forcefun = FALSE, forceapply = FALSE)

Arguments

x

A RasterArray class object.

fun

function to be applied.

margin

The MARGIN parameter of the apply function. If set to NULL then the fun will be applied to the entire stack, producing a single layer.

na.rm

Remove NA values, if supported by 'fun' (only relevant when summarizing a multilayer Raster object into a RasterLayer)

forcefun

logical. Force calc to not use fun with apply; for use with ambiguous functions and for debugging (see Details)

forceapply

logical. Force calc to use fun with apply; for use with ambiguous functions and for debugging (see Details)

Details

The method is an extension of the calc function. The strucuture expressed as the RasterArray's dimensions allows the calculations to be iterated for different margins of the array, similarly to the apply function, controlled by the margin argument.

Value

A RasterLayer or RasterArray class object.

Examples

data(dems)

d2 <- cbind(dems, dems)
double <- calc(d2, margin=1, fun=sum)

chronosphere

Earth System History Variables

v0.4.1
CC BY 4.0
Authors
Adam T. Kocsis, Nussaibah B. Raja
Initial release
2021-04-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.