collapse_by_taxonomy: Collapse by taxonomy

View source: R/collapse_by_taxonomy.r

collapse_by_taxonomyR Documentation

Collapse by taxonomy

Description

Collapses taxa according to the taxonomy object or a given factor

Usage

collapse_by_taxonomy(...)

## Default S3 method:
collapse_by_taxonomy(
  Tab,
  Tax,
  Group = NULL,
  level = 4,
  FUN = sum,
  sepchar = ";"
)

## S3 method for class 'Dataset'
collapse_by_taxonomy(Dat, Group = NULL, level = 4, FUN = sum, sepchar = ";")

Arguments

Tab

An abundance matrix with samples as columns and taxa as rows

Tax

A Taxonomy data.frame as defined by create_dataset

Group

If NULL, then the "Taxonomy" column of the Taxonomy data.frame will be used. If not NULL, it can be either a column number or name (i.e. character string), indicating which column of the Taxonomy data.frame to use as grouping factor. It can also be a factor or vector that can be coerced into factor.

level

If Group is NULL, the taxonomy level to use from the Taxonomy column.

FUN

Which function to use to aggregate

sepchar

Separator character for taxonomy levels.

Value

The default method returns a numeric matrix.

The Dataset method returns a Dataset object when Dat includes a Map element (see create_dataset). When the Map element is missing it returns a matrix object.

Author(s)

Sur Herrera Paredes

See Also

create_dataset

Examples

library(AMOR)
data(Rhizo)
data(Rhizo.map)
data(Rhizo.tax)

Dat <- create_dataset(Tab = Rhizo, Map = Rhizo.map, Tax = Rhizo.tax)
Dat.phyl <- collapse_by_taxonomy(Dat = Dat, level = 4)

# The followwing returns a matrix
Dat.collapsed1 <- collapse_by_taxonomy(Dat$Tab, Dat$Tax)

# The following returns a dataset object
Dat.collapsed2 <- collapse_by_taxonomy(Dat=Dat)

surh/AMOR documentation built on Feb. 21, 2023, 6:31 a.m.