Compute summary statistics for cells, either across layers or between layers (parallel summary).
The following summary methods are available for SpatRaster: any, all, max, min, mean, median, prod, range, stdev, sum, which.min, which.max
. See modal
to compute the mode and app
to compute summary statistics that are not included here.
Because generic functions are used, the method applied is chosen based on the first argument: "x
". This means that if r
is a SpatRaster, mean(r, 5)
will work, but mean(5, r)
will not work.
The mean
method has an argument "trim" that is ignored.
The stdev
method returns the population standard deviation, computed as:
f <- function(x) sqrt(sum((x-mean(x))^2) / length(x))
This is different than the sample standard deviation returned by sd
(which uses n-1
as denominator). Function f
above is equivalent to function g
below
g <- function(x) sqrt(sum((x-mean(x))^2) / length(x))