mean,GRaster-method | R Documentation |
These functions can be applied to a "stack" of GRaster
s with two or more layers. They return a single-layered GRaster
. If you want to summarize across cells in a raster (e.g., calculate the mean value of all cells on a raster), use global()
. Options include:
Numeration: count()
(number of non-NA
cells), sum()
.
Central tendency: mean()
, mmode()
(mode), median()
.
Extremes: min()
, max()
, which.min()
(index of raster with the minimum value), which.max()
(index of the raster with the maximum value)
Dispersion: range()
, stdev()
(standard deviation), var()
(sample variance), varpop()
(population variance), nunique()
(number of unique values), quantile()
(use argument probs
), skewness()
, and kurtosis()
.
NA
s: anyNA()
(any cells are NA
?), allNA()
(are all cells NA
?)
## S4 method for signature 'GRaster'
mean(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
mmode(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
median(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
count(x)
## S4 method for signature 'GRaster'
sum(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
min(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
max(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
which.min(x)
## S4 method for signature 'GRaster'
which.max(x)
## S4 method for signature 'numeric'
sdpop(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
varpop(x, na.rm = FALSE)
## S4 method for signature 'numeric'
varpop(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
stdev(x, pop = TRUE, na.rm = FALSE)
## S4 method for signature 'GRaster'
var(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
nunique(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
skewness(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
kurtosis(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
range(x, na.rm = FALSE)
## S4 method for signature 'GRaster'
quantile(x, prob, na.rm = FALSE)
## S4 method for signature 'GRaster'
anyNA(x)
## S4 method for signature 'GRaster'
allNA(x)
x |
A |
na.rm |
Logical: If |
pop |
Logical (for |
prob |
Numeric: Quantile to calculate. Used for |
A GRaster
.
if (grassStarted()) {
# Setup
library(sf)
library(terra)
# Example data
madChelsa <- fastData("madChelsa")
# Convert a SpatRaster to a GRaster
chelsa <- fast(madChelsa)
chelsa # 4 layers
# Central tendency
mean(chelsa)
mmode(chelsa)
median(chelsa)
# Statistics
nunique(chelsa)
sum(chelsa)
count(chelsa)
min(chelsa)
max(chelsa)
range(chelsa)
skewness(chelsa)
kurtosis(chelsa)
stdev(chelsa)
stdev(chelsa, pop = FALSE)
var(chelsa)
varpop(chelsa)
# Which layers have maximum/minimum?
which.min(chelsa)
which.max(chelsa)
# Regression
# Note the intercept is different for fasterRaster::regress().
regress(chelsa)
regress(madChelsa, 1:nlyr(madChelsa))
# Note: To get quantiles for each layer, use global().
quantile(chelsa, 0.1)
# NAs
madForest2000 <- fastData("madForest2000")
forest2000 <- fast(madForest2000)
forest2000 <- project(forest2000, chelsa, method = "near")
chelsaForest <- c(chelsa, forest2000)
nas <- anyNA(chelsaForest)
plot(nas)
allNas <- allNA(chelsaForest)
plot(allNas)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.