Adds a column to x with a summary of the raster cells in each unit, for
example the total population of every soum or the mean elevation of every
aimag.
Usage
mn_zonal(
r,
x = NULL,
fun = c("sum", "mean", "min", "max", "median"),
name = "value",
exact = TRUE
)Arguments
- r
A
terraSpatRaster (one layer), such as frommn_population().- x
An
sfobject of polygons, such asmn_soums(). Defaults to the aimags.- fun
Summary function name:
"sum"(default),"mean","min","max"or"median".- name
Name of the new column.
- exact
If
TRUE(default), weight sums and means by the fraction of each cell covered by the polygon. This assumes uniform values within cells. Means weight cell fractions, not physical cell areas. Median requiresexact = FALSE. Missing coverage returnsNA, not zero.
See also
Other raster layers:
mn_elevation(),
mn_landcover(),
mn_population()
Examples
soum_pop <- mn_zonal(mn_population(2025), mn_soums(), name = "population")
mn_map(soum_pop, fill = population / area_km2, trans = "log10")