Compute global statistics, that is summarized values of an entire SpatRaster.
If x
is very large global
can fail, except when fun
is one of these built-in functions "mean", "min", "max", "sum", "prod", "range" (min and max), "rms" (root mean square), "sd" (sample standard deviation), "std" (population standard deviation), "isNA" (number of cells that are NA), "notNA" (number of cells that are not NA).
The reason that this can fail with large raster and a custom function is that all values need to be loaded into memory. To circumvent this problem you can run global
with a sample of the cells.
You can compute a weighted mean or sum by providing a SpatRaster with weights.