【问题标题】:Dendrogram in R. How to make new tables by each clusterR中的树状图。如何按每个集群创建新表
【发布时间】:2013-11-24 13:13:58
【问题描述】:

enter image description here

library(mlbench)
library(stats)


College <- read.csv("colleges.XL.csv", header=T) ## this data has 23 columns
na.college<- na.omit(College)

row.names(na.college) <- NULL

na.college[, c(4:23)] <- scale(as.matrix(na.college[,c(-1,-2,-3)]))
###before making dendrogram, standardization is needed.

plot(hc<-hclust(dist(na.college[,c(-1,-2,-3)]),method="complete"),hang=-1)
##now the dendrogram is drawn.

groups <- cutree(hc, k=10) # cut tree into 5 clusters
# draw dendogram with red borders around the 5 clusters 
rect.hclust(hc, k=10, border="red")
## identifying 10 clusters by red borders

我想根据这个树状图制作一些表格。我有 10 个集群,每个集群都有以观察数表示的元素(我可以细化树状图底部的观察数)。由于我可以将树状图打印为 pdf 文件,因此我可以通过拖放复制所有观察编号。

现在的问题是,如何通过观察数字制作数据表? 我想制作列与树状图原始数据“na.college”相同的表。

我想制作第二个集群的数据表,但不知道怎么做。

如果你有任何答案,请告诉我。

【问题讨论】:

    标签: r cluster-analysis dendrogram


    【解决方案1】:

    试试这个:

    # your matrix dimensions have to match with the clustering results
    # remove any columns from na.college, as you did for clustering
    mat <- na.college[,-c(1:3)]
    
    # select the data based on the clustering results
    cluster_2 <- mat[which(groups==2),]
    

    如果您想保存所有集群,最好使用list

    # each list entry will correspond to the cluster number
    clust_list <- lapply(sort(unique(groups)), function(x) mat[which(groups==x),])
    
    # to retrieve i.e cluster 2:
    cluster_2 <- clust_list[[2]]
    

    【讨论】:

    • 谢谢,但我还是有问题。
    • cluster_2 [.data.frame(mat, , which(groups == 2)) : undefined columns selected" 出现错误信息
    • cluster_2
    • 感谢安德烈提出这个问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-17
    • 2019-02-13
    • 2019-09-09
    • 2015-07-05
    • 2020-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多