2

I have a dendrogram split into 4 clusters. I want to extract the cluster membership for each element in a table. Can someone please advise?

hc <- hclust(dist(USArrests), "complete")
par(cex=0.7, mar=c(5, 8, 4, 1))
plot(hc, xlab="", ylab="", main="", sub="", axes=FALSE)
par(cex=1)
title(xlab="", ylab="", main="Violent crime rates by US state")
axis(2)
rect.hclust(hc,k=4, border = 3:4)
SriniShine
  • 1,089
  • 5
  • 26
  • 46
  • Thank you @scoa. I tried to create a data frame with the State and Cluster_ID. d = data.frame(State = c(row.names(USArrests)),Cluster_ID = cutree(hc,k=4)). The thing is the State names are being displayed twice (in 2 columns). Can you please advise on how to remove one set of State names? – SriniShine Aug 29 '15 at 15:30
  • 1
    one is the variable `d$State` and the other one is the row names, which you can access with `row.names(d)`. You can either omit State from the data.frame creation (`d <- data.frame(Cluster_ID=cutree(hc,k=4))`) or use `row.names(d) <- NULL` – scoa Aug 29 '15 at 15:58
  • 1
    @scoa Why don't you just post as an answer?? – jlhoward Aug 29 '15 at 16:31
  • 1
    possible duplicate of [How to make R output text details about a dendrogram object?](http://stackoverflow.com/questions/31480427/how-to-make-r-output-text-details-about-a-dendrogram-object) – scoa Aug 29 '15 at 17:20

0 Answers0