zonal

0th

Percentile

Zonal statistics

Compute zonal statistics. That is, cross-tabulate the values of a RasterLayer based on a "zones" RasterLayer.

Keywords
spatial
Usage
zonal(raster, zones, stat='mean', na.rm=TRUE, progress)
Arguments
raster
A RasterLayer object
zones
A RasterLayer object; with codes representing zones that are treated as integer values
stat
The function to be applied. Either as character: 'mean', 'min', 'max', 'sum'; or a function (see Details)
na.rm
Logical. If TRUE, NA will be removed from the computations and the result will only be NA if all cells in a zone are NA
progress
Character. Valid values are "text", "tcltk", "windows" (on that platform only) and ""
Details

If stat is a function, zonal will fail (gracefully) for very large RasterLayers

Value

  • A data frame with a value for each zone

Aliases
  • zonal
Examples
r <- raster(ncols=10, nrows=10)
r[] <- runif(ncell(r)) * 1:ncell(r)
z <- r
z[] <- rep(1:5, each=20)
zonal(r, z, 'mean')
zonal(r, z, 'min')
zonal(r, z, 'sum')
# using a function, rather than a character value
zonal(r, z, sum)
Documentation reproduced from package raster, version 1.0.0-1, License: GPL (>= 3)

Community examples

Looks like there are no examples yet.