Skip to contents

cluster_samples() clusters the samples into n clusters and adds these clusters to a new variable "cluster" in the sample table.

Usage

cluster_samples(ta, n_clusters)

Arguments

ta

A tidytacos object.

n_clusters

The number of desired clusters.

Value

A tidytacos object with a cluster column in the samples 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.

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)