Learn R Programming

terra (version 1.8-86)

Math-methods: General mathematical methods

Description

Standard mathematical methods for computations with SpatRasters. Computations are local (applied on a cell by cell basis). If multiple SpatRasters are used, these must have the same extent and resolution. These have been implemented:

abs, sign, sqrt, ceiling, floor, trunc, cummax, cummin, cumprod, cumsum, log, log10, log2, log1p, acos, acosh, asin, asinh, atan, atanh, exp, expm1, cos, cosh, sin, sinh, tan, tanh, round, signif

Instead of directly calling these methods, you can also provide their name to the math method. This is useful if you want to provide an output filename.

The following methods have been implemented for SpatExtent: round, floor, ceiling

round has also been implemented for SpatVector, to round the coordinates of the geometries.

Usage

# S4 method for SpatRaster
sqrt(x)

# S4 method for SpatRaster log(x, base=exp(1))

# S4 method for SpatRaster round(x, digits=0)

# S4 method for SpatRaster math(x, fun, digits=0, filename="", overwrite=FALSE, ...)

# S4 method for SpatVector round(x, digits=4)

# S4 method for SpatRaster cumsum(x)

Arguments

Value

SpatRaster or SpatExtent

See Also

See app to use mathematical functions not implemented by the package, and Arith-methods for arithmetical operations. Use roll for rolling functions.

Examples

Run this code
r1 <- rast(ncols=10, nrows=10)
v <- runif(ncell(r1))
v[10:20] <- NA
values(r1) <- v
r2 <- rast(r1)
values(r2) <- 1:ncell(r2) / ncell(r2)
r <- c(r1, r2)

s <- sqrt(r)
# same as 
math(r, "sqrt")

round(s, 1)

cumsum(r)

Run the code above in your browser using DataLab