Bonjour, I would like to convert an adjacency list (3 columns ) to an adjacency matrix. In this forum I have found multiple examples on how to convert an edge list to an adjacency matrix. I successfully managed to do it for a two columns list. I have tried all the solutions I could find on the web but it seems that I missing a little step.
What I tried
My variables are User, Country, books
User<-c("maman","sophia","Antoine")
Country<-c("Canada","USA","Mexico")
books<-c("Coelho","Rimbaud","The flight")
dat<-data.frame(User, Country,books)
User | Country | books
maman | Canada | Coelho
sophia| USA | Rimbaud
Antoine| Mexico | The flight
First attempt
library(igraph)
m<-as.matrix(dat)
g<-graph.adjacency(m, mode="directed") ### If that worked I could have used
"get.adjacency"
Second attempt
Tried to convert the data to an edge list but I got an error since there is three columns
el<-as.matrix(dat)
g=graph.edgelist(el,directed=TRUE) # turns
Excepted output
maman sophia Antoine Canada USA Mexico Coelho Rimbaud The fligth
maman 1 0 1 0 0 0 0 1 0
sophia 0 0 0 0 1 0 1 0 1
Antoine 0 1 1 0 1 0 0 1 0
Canada 1 0 1 0 0 1 0 1 1
USA 0 0 0 1 0 0 0 0 1
Mexico 0 0 0 0 1 1 1 0 0
Coelho 0 0 1 1 0 1 0 1 0
Rimbaud 1 0 1 1 0 0 0 1 1
The fligth 0 1 0 0 1 1 0 0 1
I would like to see the interactions between all the vertices. Something similar to this: http://sna.stanford.edu/sna_R_labs/output/lab_1/1.3_Krackhardt_Friendship.pdf
Any help or indication would be appreciated!!!