Pools abundances from samples according to a grouping factor.

pool_samples(x, ...)

# S3 method for default
pool_samples(x, groups, FUN = sum, return.dataset = FALSE)

# S3 method for Dataset
pool_samples(x, groups, FUN = sum, return.dataset = FALSE)

Arguments

x

Either a numerical matrix or a Dataset object. For a numerical matrix, samples are given as columns and taxa as rows.

groups

For the default and Dataset methods this can be either a vector or factor specifying to which group each sample belongs. Vectors will be converted to a factor with the factor function. It must be of the same length as ncol(x). For the Dataset method, it can also be a single character string or numeric value indicating the column from x$Map to be used as a grouping factor.

FUN

Function to apply when collapsing the data. Defaults to sum, which is ideal for count data. For proportioanl data mean or median might be more appropriate. Any function that takes a vector of numbers and returns a single numeric value can be used.

return.dataset

Logical, if TRUE returns a dataset

Value

The default method returns a matrix object, unless return.dataset is TRUE, in which case it returns a Dataset.

The Dataset method returns a Dataset object when Dat includes a Tax element (see create_dataset); when the Tax element is missing it returns a matrix object. If return.dataset is TRUE, return a dataset

Details

Wrapper for collapse_matrix. This function is useful to calculate per-group summary statistics per taxon.

The default method takes an abundance matrix and a grouping factor, then applies the aggregating function FUN to the groups of samples defined by the grouping factor.

The Dataset method takes a Dataset object and obtains the grouping factor from the Map element.

Examples

library(AMOR) data(Rhizo) data(Rhizo.map) data(Rhizo.tax) Dat <- create_dataset(Rhizo,Rhizo.map,Rhizo.tax) # The following returns a numeric matrix Collapsed1 <- pool_samples(x = Dat$Tab,groups = Dat$Map$fraction) # The following returns a Dataset Collapsed2 <- pool_samples(x = Dat,groups = "fraction") # You can also directly pass a grouping factor to the Dataset method Collapsed3 <- pool_samples(x = Dat,groups = Dat$Map$fraction) # A way to calculate the overall counts per taxa res <- pool_samples(Dat$Tab, groups = rep("all", length.out = ncol(Rhizo)))