How to use a matrix to display a relation in R?

I have an x ​​list here: enter image description here

I want to show the relationship between these elements: enter image description here

Can someone tell me how to do this in R? Thank you very much!

+1
source share
1 answer

First create a matrix of all pairs from the source list:

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

Then use one of the methods shown here: Matrix pair interaction in R . I like the one that uses graph theory tools :-)

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
+1
source

Source: https://habr.com/ru/post/1649851/


All Articles