Learn R Programming

terra (version 0.2-7)

global: global statistics

Description

Compute global statistics, that is summarized values of an entire SpatRaster.

If stat is a true function, global will fail (gracefully) for very large SpatRasters, but it will in most cases work for functions that can be defined as by a character argument ("mean", "min", "max", or "sum").

If a function is used, it should accept a na.rm argument (or at least a ... argument)

Usage

# S4 method for SpatRaster
global(x, fun="mean", na.rm=TRUE,  ...)

Arguments

x

SpatRaster

fun

function to be applied to summarize the values by zone. Either as character: 'mean', 'sd', 'min', 'max', 'sum'; or, for relatively small SpatRasters, a proper function

na.rm

logical. If TRUE, NA values in x are ignored

...

Additional arguments. None implemented

Value

A matrix with a value for each layer

See Also

See zonal for "zonal" statistics" and reduce or local for "local" statistics, and extract for summarizing values for polygons

Examples

Run this code
# NOT RUN {
r <- rast(ncols=10, nrows=10)
values(r) <- 1:ncell(r)
global(r, "sum")
global(r, "mean")
# }

Run the code above in your browser using DataLab