Reputation: 673
Hello I've been trying to convert my dataframe to a graph object using igraph package.
g = as.matrix(votings[,1:2])
g = graph.edgelist(votings, directed = TRUE)
Error in graph.edgelist(votings) : graph_from_edgelist expects a matrix with two columns
I've also tried drop = FALSE, as other posts suggested.
g = graph.edgelist(votings[,1:2, drop = FALSE))
Error in graph.edgelist(votings) : graph_from_edgelist expects a matrix with two columns
Any ideas what could be wrong with my code? The first two columns of votings contain character strings (names).
Upvotes: 0
Views: 2544
Reputation: 673
So I tried graph_from_data_frame and it worked as Gabor Casardi suggested. Thank you! But if you want to use graph.edgelist, this works.
library(igraph)
g = graph_from_edgelist(as.matrix(votings[,1:2, drop = FALSE], directed = TRUE))
Upvotes: 1