在 R 中找到簇的交集
To find intersection of clusters in R
假设我已经完成了多项操作并创建了相关值的聚类向量,如下所示
D <- matrix(rexp(10*10,rate=.1), ncol=10) #create a randomly filled 10x10 matrix
C <- matrix(rexp(10*10,rate=.1),ncol=10)
DCor <- cor(D) # generate correlation matrix
CCor <- cor(C)
DUpper<- DCor[upper.tri(DCor)] # extract upper triangle
CUpper<- CCor[upper.tri(CCor)]
ClusterD <- kmeans(DUpper,3) # cluster correlations
ClusterC <- kmeans(CUpper,3)
ClusterC <- cbind(c(1:45),matrix(ClusterC$cluster)) # add row numbers as column
ClusterD <- cbind(c(1:45),matrix(ClusterD$cluster))
我想生成一个矩阵显示每个集群组的交集。在这个矩阵中,5行同时属于C1和D2组。
如何生成这样的矩阵?
在 cbind 行之前,你可以这样做:
table(ClusterC$cluster, ClusterD$cluster)
假设我已经完成了多项操作并创建了相关值的聚类向量,如下所示
D <- matrix(rexp(10*10,rate=.1), ncol=10) #create a randomly filled 10x10 matrix
C <- matrix(rexp(10*10,rate=.1),ncol=10)
DCor <- cor(D) # generate correlation matrix
CCor <- cor(C)
DUpper<- DCor[upper.tri(DCor)] # extract upper triangle
CUpper<- CCor[upper.tri(CCor)]
ClusterD <- kmeans(DUpper,3) # cluster correlations
ClusterC <- kmeans(CUpper,3)
ClusterC <- cbind(c(1:45),matrix(ClusterC$cluster)) # add row numbers as column
ClusterD <- cbind(c(1:45),matrix(ClusterD$cluster))
我想生成一个矩阵显示每个集群组的交集。在这个矩阵中,5行同时属于C1和D2组。
如何生成这样的矩阵?
在 cbind 行之前,你可以这样做:
table(ClusterC$cluster, ClusterD$cluster)