if (FALSE) {
# Parse data for examples
x = parse_tax_data(hmp_otus, class_cols = "lineage", class_sep = ";",
class_key = c(tax_rank = "taxon_rank", tax_name = "taxon_name"),
class_regex = "^(.+)__(.+)$")
# Apply a function to every value without grouping
calc_group_stat(x, "tax_data", function(v) v > 3)
# Calculate the means for each group
calc_group_stat(x, "tax_data", mean, groups = hmp_samples$sex)
# Calculate the variation for each group
calc_group_stat(x, "tax_data", sd, groups = hmp_samples$body_site)
# Different ways to use only some columns
calc_group_stat(x, "tax_data", function(v) v > 3,
cols = c("700035949", "700097855", "700100489"))
calc_group_stat(x, "tax_data", function(v) v > 3,
cols = 4:6)
calc_group_stat(x, "tax_data", function(v) v > 3,
cols = startsWith(colnames(x$data$tax_data), "70001"))
# Including all other columns in ouput
calc_group_stat(x, "tax_data", mean, groups = hmp_samples$sex,
other_cols = TRUE)
# Inlcuding specific columns in output
calc_group_stat(x, "tax_data", mean, groups = hmp_samples$sex,
other_cols = 2)
calc_group_stat(x, "tax_data", mean, groups = hmp_samples$sex,
other_cols = "otu_id")
# Rename output columns
calc_group_stat(x, "tax_data", mean, groups = hmp_samples$sex,
out_names = c("Women", "Men"))
}
Run the code above in your browser using DataLab