global: Summary statistics for GRasters

global,GRaster-methodR Documentation

Summary statistics for GRasters

Description

global() calculates a summary statistic across all the cells of a GRaster. It returns a single value for each layer of the raster.

Usage

## S4 method for signature 'GRaster'
global(x, fun = "mean", probs = seq(0, 1, 0.25), ...)

## S4 method for signature 'missing'
global(x, ...)

Arguments

x

A GRaster or missing. If missing, then a vector of all of the accepted function names is returned.

fun

Character vector: The name of the function(s):

  • "*": All of the functions below.

  • "cv": Sample coefficient of variation (expressed as a proportion of the mean).

  • "cvpop": Population coefficient of variation (expressed as a proportion of the mean).

  • "max" and "min": Highest and lowest values across non-NA cells. NB: minmax() is faster.

  • "mean" (default): Average.

  • "meanAbs": Mean of absolute values.

  • "median": Median.

  • "quantile": Quantile (see also argument probs).

  • "range": Range. Note that following terra::global(), the minimum and maximum are reported, not the actual range.

  • "sd": Sample standard deviation (same as stats::sd()).

  • "sdpop": Population standard deviation.

  • "sum": Sum.

  • "var": Sample variance (same as stats::var()).

  • "varpop": Population variance.

probs

Numeric within the range from 0 to 1: Quantile(s) at which to calculate quantile.

...

Other arguments (unused).

Value

If x is missing, the function returns a character vector of all accepted function names. If x is a GRaster, a data frame with the specified statistics is returned.

See Also

terra::global() and GRASS module r.univar

Examples

if (grassStarted()) {

# Setup
library(terra)

# Example data
madElev <- fastData("madElev")

# Convert a SpatRaster to a GRaster:
elev <- fast(madElev)

# What functions can we use with global()?
global()

# Calculate global statistics:
global(elev, fun = c("mean", "var", "varpop"))
global(elev, "quantile", probs = c(0.25, 0.5, 0.75))

global(elev, "*") # calculate all available functions

}

adamlilith/fasterRaster documentation built on Oct. 26, 2024, 4:06 p.m.