This function calculates the average of species values in each planning unit. By default all polygons will be treated as having separate ids.

calcSpeciesAverageInPus(x, ...)

# S3 method for SpatialPolygons
calcSpeciesAverageInPus(x, y, ids = seq_len(nlayers(y)), ncores = 1, ...)

# S3 method for SpatialPolygonsDataFrame
calcSpeciesAverageInPus(
  x,
  y,
  ids = seq_len(nlayers(y)),
  ncores = 1,
  field = NULL,
  ...
)

Arguments

x

sp::SpatialPolygons() or sp::SpatialPolygonsDataFrame() object.

...

not used.

y

raster::raster(), raster::stack(), or raster::brick() object.

ids

integer vector of ids. Defaults to indices of layers in argument to y.

ncores

integer number of cores to use for processing. Defaults to 1.

field

integer index or character name of column with planning unit ids. Valid only when x is a sp::SpatialPolygonsDataFrame() object. Default behavior is to treat each polygon as a different planning unit.

Value

base::data.frame() with sum of raster values in each polygon.

Examples

# simulate data sim_pus <- sim.pus(225L) sim_spp <- lapply(c("uniform", "normal", "bimodal"), sim.species, n = 1, res = 1, x = sim_pus) # calculate average for 1 species puvspr1.dat <- calcSpeciesAverageInPus(sim_pus, sim_spp[[1]]) # calculate average for multiple species puvspr2.dat <- calcSpeciesAverageInPus(sim_pus, stack(sim_spp))