我已经使用 as.undirected 在 igraph 中将有向图转换为无向图。我现在想将其导出到数据框,以便查看边缘和重量。但是,当我尝试使用 as_data_frame 这样做时,我最终得到了一个损坏的数据框,同时使用了默认的“what”选项和“both”。我无法真正共享数据,但下面是我正在使用的代码。还有其他方法吗?
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")
我认为您应该使用
edge.attr.comb = "sum"
,而不是 igraph_opt("sum")
,您可以通过在控制台中键入 igraph_opt
来找到 ?igraph_opt
的用法。
如你所见
> igraph_opt("edge.attr.comb")
$weight
[1] "sum"
$name
[1] "concat"
[[3]]
[1] "ignore"