Merge samples based on a sample variable or factor.
The purpose of this method is to merge/agglomerate the sample indices of a phyloseq object according to a categorical variable contained in a sample_data or a provided factor.
merge_samples(x, group, fun=mean) ## S4 method for signature 'sample_data' merge_samples(x, group, fun = mean) ## S4 method for signature 'otu_table' merge_samples(x, group) ## S4 method for signature 'phyloseq' merge_samples(x, group, fun = mean)
x |
(Required). An instance of a phyloseq class that has sample indices. This includes
|
group |
(Required). Either the a single character string matching a variable name in
the corresponding sample_data of |
fun |
(Optional). The function that will be used to merge the values that
correspond to the same group for each variable. It must take a numeric vector
as first argument and return a single value. Default is |
NOTE: (phylo
) trees and taxonomyTable-class
are not modified by this function, but returned in the output object as-is.
A phyloseq object that has had its sample indices merged according to
the factor indicated by the group
argument. The output class
matches x
.
merge_taxa
, codemerge_phyloseq
# data(GlobalPatterns) GP = GlobalPatterns mergedGP = merge_samples(GlobalPatterns, "SampleType") SD = merge_samples(sample_data(GlobalPatterns), "SampleType") print(SD) print(mergedGP) sample_names(GlobalPatterns) sample_names(mergedGP) identical(SD, sample_data(mergedGP)) # The OTU abundances of merged samples are summed # Let's investigate this ourselves looking at just the top10 most abundance OTUs... OTUnames10 = names(sort(taxa_sums(GP), TRUE)[1:10]) GP10 = prune_taxa(OTUnames10, GP) mGP10 = prune_taxa(OTUnames10, mergedGP) ocean_samples = sample_names(subset(sample_data(GP), SampleType=="Ocean")) print(ocean_samples) otu_table(GP10)[, ocean_samples] rowSums(otu_table(GP10)[, ocean_samples]) otu_table(mGP10)["Ocean", ]
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.