roll | R Documentation |
Compute "rolling" or "moving" values, such as the "rolling average" for each cell in a SpatRaster.
See focal
for spatially moving averages and similar computations. And see cumsum
and other cum* functions to compute cumulate values.
## S4 method for signature 'SpatRaster'
roll(x, n, fun=mean, type="around", circular=FALSE,
na.rm=FALSE, filename="", ..., wopt=list())
## S4 method for signature 'numeric'
roll(x, n, fun=mean, type="around", circular=FALSE, na.rm=FALSE, ...)
x |
SpatRaster or numeric |
n |
integer > 1. The size of the "window", that is, the number of sequential cells to use in |
fun |
a function like mean, min, max, sum |
type |
character. One of "around", "to", or "from". The choice indicates which values should be used in the computation. The focal cell is always used. If type is "around", |
circular |
logical. If |
na.rm |
logical. If |
filename |
character. Output filename |
... |
additional arguments for |
wopt |
list with named options for writing files as in |
Same as x
cumsum
, focal
## numeric
roll(1:12, 3, mean)
roll(1:12, 3, mean, "to")
roll(1:12, 3, mean, circular=TRUE)
## SpatRaster
r <- rast(ncol=2, nrow=2, nlyr=10, vals=1)
r[1,2] = 2
r[2,2] = 4
roll(r, n=3, "sum", "from", na.rm=FALSE) |> values()
roll(r, n=3, "sum", "from", na.rm=TRUE) |> values()
roll(r, n=3, "sum", "from", circular=TRUE) |> values()
roll(r, n=3, "sum", "to", na.rm=TRUE) |> values()
roll(r, n=3, "sum", "around", circular=TRUE) |> values()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.