Compute global statistics, that is summarized values of an entire SpatRaster.
If x is very large global will fail, except when fun is one of "mean", "min", "max", "sum", "range" (min and max), "rms" (root mean square), "sd" (sample standard deviation), "sdpop" (population standard deviation), "isNA" (number of cells that are NA), "notNA" (number of cells that are not NA).
You can compute a weighted mean or sum by providing a SpatRaster with weights.