merge_samples2 | R Documentation |
Firstly release in the speedyseq R package by Michael R. McLaren.
This function provides an alternative to phyloseq::merge_samples()
that
better handles sample variables of different types, especially categorical
sample variables. It combines the samples in x
defined by the sample
variable or factor group
by summing the abundances in otu_table(x)
and
combines sample variables by the summary functions in funs
. The default
summary function, unique_or_na()
, collapses the values within a group to a
single unique value if it exists and otherwise returns NA. The new (merged)
samples are named by the values in group
.
merge_samples2(x, group, fun_otu = sum, funs = list(), reorder = FALSE)
## S4 method for signature 'phyloseq'
merge_samples2(x, group, fun_otu = sum, funs = list(), reorder = FALSE)
## S4 method for signature 'otu_table'
merge_samples2(x, group, fun_otu = sum, reorder = FALSE)
## S4 method for signature 'sample_data'
merge_samples2(x, group, funs = list(), reorder = FALSE)
x |
A |
group |
A sample variable or a vector of length |
fun_otu |
Function for combining abundances in the otu_table; default
is |
funs |
Named list of merge functions for sample variables; default is
|
reorder |
Logical specifying whether to reorder the new (merged) samples by name |
A new phyloseq-class, otu_table or sam_data object depending on the class of the x param
Michael R. McLaren (orcid: 0000-0003-1575-473X) modified by Adrien Taudiere
data(enterotype)
# Merge samples with the same project and clinical status
ps <- enterotype
sample_data(ps) <- sample_data(ps) %>%
transform(Project.ClinicalStatus = Project:ClinicalStatus)
sample_data(ps) %>% head()
ps0 <- merge_samples2(ps, "Project.ClinicalStatus",
fun_otu = mean,
funs = list(Age = mean)
)
sample_data(ps0) %>% head()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.