Learn R Programming

raptr (version 1.0.1)

calcSpeciesAverageInPus: 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 SpatialPolygons calcSpeciesAverageInPus(x, y, ids = seq_len(terra::nlyr(y)), ...)

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

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

Value

A base::data.frame() object.

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.

Examples

Run this code
if (FALSE) {
# 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)
}

Run the code above in your browser using DataLab