add_cluster: Add cluster number

View source: R/adders_samples.R

add_clusterR Documentation

Add cluster number

Description

add_cluster adds a new variable to the samples tibble of a tidyamplicons object defining to what cluster a sample belongs.

Usage

add_cluster(ta, n_clusters)

Arguments

ta

Tidyamplicons object.

n_clusters

Numerical. Number of desired clusters.

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 tidyamplicons object defining to what cluster a sample belongs.

Examples

# Initiate abundance matrix
x <- matrix(
 c(1500, 1300, 280, 356),
 ncol = 2
)
rownames(x) <- c("taxon1", "taxon2")
colnames(x) <- c("sample1", "sample2")

# Convert to tidyamplicons object
data <- create_tidyamplicons(x,
                     taxa_are_columns = FALSE
                     )

# Add total abundance
data <- data %>%
 add_cluster(n_clusters = 2)


SWittouck/tidyamplicons documentation built on Aug. 15, 2023, 3:14 a.m.