
For a given table in a taxmap
object, split columns by a
grouping factor and return row means in a table.
calc_group_mean(
obj,
data,
groups,
cols = NULL,
other_cols = FALSE,
out_names = NULL,
dataset = NULL
)
A tibble
A taxmap
object
The name of a table in obj$data
.
Group multiple columns per treatment/group. This should be a
vector of group IDs (e.g. character, integer) the same length as
cols
that defines which samples go in which group. When used, there
will be one column in the output for each unique value in groups
.
The columns in data
to use. By
default, all numeric columns are used. Takes one of the following inputs:
All/No columns will used.
The names of columns to use
The indexes of columns to use
Use the columns corresponding to TRUE
values.
Preserve in the output non-target columns present in the input data. New columns will always be on the end. The "taxon_id" column will be preserved in the front. Takes one of the following inputs:
No columns will be added back, not even the taxon id column.
All/None of the non-target columns will be preserved.
The names of columns to preserve
The indexes of columns to preserve
Preserve the columns corresponding to TRUE
values.
The names of count columns in the output. Must be the same
length and order as cols
(or unique(groups)
, if groups
is used).
DEPRECIATED. use "data" instead.
Other calculations:
calc_diff_abund_deseq2()
,
calc_group_median()
,
calc_group_rsd()
,
calc_group_stat()
,
calc_n_samples()
,
calc_obs_props()
,
calc_prop_samples()
,
calc_taxon_abund()
,
compare_groups()
,
counts_to_presence()
,
rarefy_obs()
,
zero_low_counts()
# 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 = "^(.+)__(.+)$")
# Calculate the means for each group
calc_group_mean(x, "tax_data", hmp_samples$sex)
# Use only some columns
calc_group_mean(x, "tax_data", hmp_samples$sex[4:20],
cols = hmp_samples$sample_id[4:20])
# Including all other columns in ouput
calc_group_mean(x, "tax_data", groups = hmp_samples$sex,
other_cols = TRUE)
# Inlcuding specific columns in output
calc_group_mean(x, "tax_data", groups = hmp_samples$sex,
other_cols = 2)
calc_group_mean(x, "tax_data", groups = hmp_samples$sex,
other_cols = "otu_id")
# Rename output columns
calc_group_mean(x, "tax_data", groups = hmp_samples$sex,
out_names = c("Women", "Men"))
Run the code above in your browser using DataLab