Reputation: 1723
I am conducting a hierarchical cluster analysis by using hclust()
The code looks like this:
hc <- hclust(dist(USArrests), "ave")
Now, all I need is to get a table (or something equivalent) which contains all clusters and the observations (by their rowname, NOT number) which belong to them so that I can save it to some overall file/dataframe - e.g. Excel. (I want to run the hclust several times with different methods, variables and evaluate the results in the end.)
I now, its probably pretty easy, but I am stuck somehow... do you have any advice?
Ps.: I would also like to know how this works when using kmeans()
Upvotes: 1
Views: 4222
Reputation: 3711
hclust
does not give you the cluster groups. you can use cutree
to make cluster them.
So, if you want to cluster them in three groups;
cutree(hc,3)
if you want dataframe,
data.frame(cutree(hc,3))
for kmeans,
km<-kmeans(USArrests,3)
km$centers
Upvotes: 5