calcSpeciesAverageInPus {raptr}R Documentation

Calculate average value for species data in planning units

Description

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

Usage

calcSpeciesAverageInPus(x, ...)

## S3 method for class 'SpatialPolygons'
calcSpeciesAverageInPus(x, y, ids = seq_len(terra::nlyr(y)), ...)

## S3 method for class 'SpatialPolygonsDataFrame'
calcSpeciesAverageInPus(x, y, ids = seq_len(terra::nlyr(y)), field = NULL, ...)

## S3 method for class 'sf'
calcSpeciesAverageInPus(x, y, ids = seq_len(terra::nlyr(y)), field = NULL, ...)

Arguments

x

sf::st_as_sf() object.

...

not used.

y

terra::rast() object.

ids

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

field

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

Value

A base::data.frame() object.

Note

Although earlier versions of the package had an additional ncores parameter, this parameter has been deprecated.

Examples

## Not run: 
# simulate data
sim_pus <- sim.pus(225L)
sim_spp <- terra::rast(
  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, sim_spp)

## End(Not run)

[Package raptr version 1.0.1 Index]