add_cluster.Rd
add_cluster
adds a new variable to the samples tibble of a
tidyamplicons object defining to what cluster a sample belongs.
add_cluster(ta, n_clusters)
Tidyamplicons object.
Numerical. Number of desired clusters.
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.
# 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)