hc <- hclust(dist(USArrests))
hck5 <- cutreeIntoOrderedGroups(hc, k = 5)
table(hck5)
## compare with cutree, which does not order the groups
table(cutree(hc, k=5))
hck25 <- cutreeIntoOrderedGroups(hc, k = 2:5)
apply(hck25, 2, table)
Run the code above in your browser using DataLab