metacoder (version 0.2.0)

calc_n_samples: Count the number of samples

Description

For a given table in a taxmap object, count the number of samples with greater than zero occurrences.

Usage

calc_n_samples(obj, dataset, cols = NULL, groups = NULL, out_names = NULL,
  drop = FALSE, append = FALSE)

Arguments

obj

A taxmap object

dataset

The name of a table in obj that contains counts.

cols

The names/indexes of columns in data that have counts. By Default, all numeric columns in data are used.

groups

Group counts of 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.

out_names

The names of count columns in the output. Must be the length 1 or same length as unique(groups), if used.

drop

If groups is not used, return a vector of the results instead of a table with one column.

append

If TRUE, append results to input table and return.

Value

A tibble

See Also

Other calculations: calc_obs_props, calc_taxon_abund, compare_groups, rarefy_obs, zero_low_counts

Examples

Run this code
# NOT RUN {
# Parse dataset for example
x = parse_tax_data(hmp_otus, class_cols = "lineage", class_sep = ";",
                   class_key = c(tax_rank = "info", tax_name = "taxon_name"),
                   class_regex = "^(.+)__(.+)$")
                   
# Count samples with reads
calc_n_samples(x, dataset = "tax_data")

# Return a vector instead of a table
calc_n_samples(x, dataset = "tax_data", drop = TRUE)

# Only use some columns
calc_n_samples(x, dataset = "tax_data", cols = hmp_samples$sample_id[1:5])

# Return a count for each treatment
calc_n_samples(x, dataset = "tax_data", groups = hmp_samples$body_site)

# Rename output columns 
calc_n_samples(x, dataset = "tax_data", groups = hmp_samples$body_site,
               out_names = c("A", "B", "C", "D", "E"))

# Add results to input table
calc_n_samples(x, dataset = "tax_data", append = TRUE)
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace