globalx {enmSdmX}R Documentation

"Friendly" wrapper for terra::global() for calculating raster statistics

Description

Calculate "global" statistics across all the values in a raster. This function is a wrapper for global. That function, by default, sets na.rm = FALSE, so any cell that is NA can cause the summary statistic to also be NA (usually undesirable). The function also returns a data.frame, so often needs a further line of code to get the actual value(s). This function sets na.rm = TRUE by default, and returns a numeric vector (not a data.frame).

Usage

globalx(x, fun, na.rm = TRUE, ..., weights = NULL)

Arguments

x

A SpatRaster.

fun

A function or the name of a function (in quotes). See global for more details.

na.rm

If TRUE (default), then the function in fun will ignore NA cells.

...

Additional arguments to pass to fun.

weights

Either NULL or a SpatRaster.

Value

A numeric vector, one value per layer in x.

Examples


library(terra)

r <- rast(ncols=10, nrows=10)
values(r) <- 1:ncell(r)


global(r, 'sum') # terra
globalx(r, 'sum') # enmSdmX

global(r, "mean", na.rm=TRUE)[1, 1] # terra... same as enmSdmX::globalx


[Package enmSdmX version 1.1.2 Index]