我想提取矩阵中的链数。
问题;
[,1] [,2]
[1,] 1 3
[2,] 2 4
[3,] 3 5
[4,] 5 6
[5,] 4 7
[6,] 6 8例如,第一行中的第二个数字3与第三行中的3连接,然后第二列中的5与第二列中的5连接,第三行与第一行的5连接。从5到6到8。另外,第二行中的2与4到7相连。因此,
[1] 1 3 5 6 8
[1] 2 4 7发布于 2016-09-21 13:59:05
您可以检查igraph包:
library(igraph)
g <- graph.data.frame(as.data.frame(mat)) # convert the matrix to data frame and graph object
m <- clusters(g) # calculate the clusters of the graph based on connections
lapply(split(m$membership, m$membership), names) # split nodes based on their membership
# and extract the name of the nodes
# $`1`
# [1] "1" "3" "5" "6" "8"
# $`2`
# [1] "2" "4" "7"数据
# dput(mat)
# structure(c(1L, 2L, 3L, 5L, 4L, 6L, 3L, 4L, 5L, 6L, 7L, 8L), .Dim = c(6L, 2L))https://stackoverflow.com/questions/39618469
复制相似问题