如何使用矩阵显示R中的关系?(How to use matrix to show relations

2019-09-28 06:08发布

我有一个列表X这里:

我想说明这样的元素之间的关系:

谁能告诉我如何做到这一点的R' 非常感谢你!

Answer 1:

首先,建立从原始列表中的所有对的矩阵:

L <- list(c("John", "Mary", "Jack"), c("John", "Wendy"), c("Mary", "Wendy"))
x <- matrix(unlist(lapply(L, combn, 2, simplify = FALSE)), ncol = 2)

然后,使用在此示出的方法之一: R中的成对相互作用矩阵 。 我利用图论工具喜欢的人:-)

library(igraph)
g <- graph.edgelist(x, directed = FALSE)
get.adjacency(g)

#       John Jack Mary Wendy
# John     0    1    1     1
# Jack     1    0    1     0
# Mary     1    1    0     1
# Wendy    1    0    1     0


文章来源: How to use matrix to show relationship in R?