Hello everyone,
My question is quite simple but I struggle to get a simple answer. I created 30 clusters of trees by height and width in a field using hclust. Then what I would like is to select the individuals that are the closest to the centroid of each cluster to extract them as they will be the ones I use for my samples. I already managed to extract the labels of individuals per Cluster using get_subdendrograms and transfer them in a data frame using a loop, but then I loose the information of which individual is the closest to the centroid of clusters.
Anyone that could help ?
here is my script :
dend = donneereduit2 %>%
dist() %>%
hclust() %>%
as.dendrogram() %>%
color_branches(k = 30)
plot(dend)
dend_list <- get_subdendrograms(dend, 30)
laliste = lapply(dend_list, labels)
laliste
df <- data.frame(
Nom_arbre = character(),
Num_cluster = integer(),
stringsAsFactors = FALSE
)
Nom_arbre = c()
clusters = c()
for (i in (1:30)){
for (i in (1:length(laliste))){
for (k in (1:lengths(laliste[i]))){
row_j <- c(laliste[[i]][k], i)
df[nrow(df)+1,] <- row_j
}
}