R/collapse_table.R
collapse_table.RdCollapses an abundance table by a specified taxonomic rank (e.g. genus, family, phylum), summing counts across features that share the same taxonomy. Features with lower taxonomic resolution than the selected level are retained unchanged. Optionally converts counts to relative abundance and exports the collapsed table to a tab-delimited file.
collapse_table(
table,
metadata,
level = "genus",
rel_abun = FALSE,
export_txt = FALSE,
file_name = "collapsed_table.txt"
)A data frame containing an OTU/ASV abundance table. Must include a column with OTUID, one with taxonomy and sample columns with numeric counts.
A data frame containing sample metadata. The first column is used to define the order of samples in the output table.
Character string specifying the taxonomic level to collapse to. ("kingdom","phylum","class","order","family","genus" or"species".
Logical. If TRUE, converts counts to relative abundance (%) per sample.
Logical. If TRUE, exports the collapsed table as a tab-delimited text file.
Character. Name of the output file when export_txt = TRUE.
a table collapsed by taxonomic level
collapse_table(
table = table,
metadata = metadata,
level = "genus",
rel_abun = FALSE,
export_txt = FALSE
)
#> Error in table[, c("taxonomy", setdiff(names(table), "taxonomy"))]: object of type 'closure' is not subsettable