rigraphsocial-networking

Export results of as.undirected in igraph to a data frame


I have converted a directed graph to an undirected one in igraph using as.undirected. I now want to export this to a data frame so I can look through the edges and weight. However, when I try to do so using as_data_frame I end up with a corrupted data frame, using both the default "what" option and "both". I can't really share the data, but below is the code I'm using. Is there another way to do this?

g <- graph.data.frame(edges, directed = TRUE)
E(g)$weight <- edges$weightvar
g2 <- as.undirected(g, mode = "collapse", edge.attr.comb = igraph_opt("sum"))
out <- as_data_frame(g2, what = "both")

Solution

  • I think you should use edge.attr.comb = "sum", rather than igraph_opt("sum"), and you find the use of igraph_opt by typing ?igraph_opt in the console.

    As you can see

    > igraph_opt("edge.attr.comb")
    $weight
    [1] "sum"
    
    $name
    [1] "concat"
    
    [[3]]
    [1] "ignore"