mx_collapse: Collapse columns in a species matrix

Description Usage Arguments Details Value Examples

Description

Collapse two matrix or data.frame columns into one, where new values are the min, max, or mean. Appropriate for synonymizing species (columns) in a species abundance matrix.

Usage

1
mx_collapse(x, c1, c2, method = "max", ...)

Arguments

x

array of species data, where rows = SUs and cols = species, containing the two columns to be collapsed and synonymized

c1

column name (to be retained)

c2

column name (to be omitted)

method

method to retain values, one of 'min', 'max' or 'mean'

...

further arguments passed to other methods

Details

Appropriate for synonymizing species (columns) in a species abundance matrix. For example, if a species occurs twice in a plot, simply take the highest, lowest, or mean of observed values. The name of the first column is retained, the second column is removed.

Value

Modified dataframe or matrix, with one fewer column than the original.

Examples

1
2
3
4
5
6
7
8
# species abundance data
set.seed(1917)
spe <- data.frame(matrix(rnorm(30, 10, 50), 10, 3))
spe[spe < 0] <- 0
colnames(spe) <- c('Acer rubrum','Acer saccharum','Acer negundo')
spe
mx_collapse(spe, c1='Acer rubrum', c2='Acer negundo')
mx_collapse(spe, c1='Acer rubrum', c2='Acer negundo', method='mean')

phytomosaic/ecole documentation built on Jan. 2, 2022, 11:24 p.m.