cluster_samples()
clusters the samples into n clusters and adds these
clusters to a new variable "cluster" in the sample table.
Details
This function calculates the Bray-Curtis distance between samples followed by hierarchical average linkage clustering of samples. The user provides a number of desired clusters which will be used to assign the samples to. A new variable named "cluster" will be added to the samples tibble of a tidytacos object defining to what cluster a sample belongs.
See also
Other sample-modifiers:
add_alpha()
,
add_alphas()
,
add_metadata()
,
add_ord()
,
add_sample_clustered()
,
add_spike_ratio()
,
add_total_absolute_abundance()
,
add_total_count()
,
add_total_density()
Examples
# Initiate count matrix
x <- matrix(
c(1500, 1300, 280, 356),
ncol = 2
)
rownames(x) <- c("taxon1", "taxon2")
colnames(x) <- c("sample1", "sample2")
# Convert to tidytacos object
data <- create_tidytacos(x,
taxa_are_columns = FALSE
)
# Add total abundance
data <- data %>%
cluster_samples(n_clusters = 2)