cutree
gives you a vector of cluster indices
hc <- hclust(dist(USArrests))
clusters.idx <- cutree(hc, k = 5) # create five clusters
head(clusters.idx)
# Alabama Alaska Arizona Arkansas California Colorado
# 1 1 1 2 1 2
which you can use to split
your original data:
clusters <- split(USArrests, clusters.idx)
Here, clusters
is a list of data.frames. You can for example access the first cluster using clusters[[1]]
.