Learn R Programming

chronosphere (version 0.4.1)

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 RasterArray,`function`
calc(x, fun, margin = NULL, na.rm = NULL, forcefun = FALSE, forceapply = FALSE)

Value

A RasterLayer or RasterArray class object.

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.

Examples

Run this code
data(dems)

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

Run the code above in your browser using DataLab