0

ここに画像の説明を入力

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」の元データと同じカラムのテーブルを作りたいです。

2番目のクラスターのデータテーブルを作りたいのですが、やり方がわかりません。

回答がありましたら、お知らせください。

4

1 に答える 1

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]]
于 2013-11-24T13:43:05.550 に答える