简体   繁体   中英

Get indices of cutree of hclust

Its a very basic question, unfortunately I do not know how to ask it. Lets say I have the following code for clustering using hclust:

hc <- hclust(dist(USArrests), "ave")
s = cutree(hc,k=2)

Lets assume sort(s) gives the following result:

Alabama Alaska Arizona Delaware Florida
   1     1       1        2       2

How can I get Alabama Alaska Arizona Delaware Florida in a list without the bottom cluster number getting appended to it.

You can get the names from the vector itself (as mentioned by @AEBilgrau) names(sort(s)) . Also, in this particular case, the cutree output will be in the order of the labels of the tree, so you could also use labels(hc) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM