merge_samples2 | R Documentation |
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 |
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.