如何在 R 中存储图形(来自 igraph 包)?

How to store graphs (from the igraph package) in R?

是否可以将一组图形(来自igraph)存储在向量或其他数据结构中?

我正在尝试这样做:

require('igraph')

g1 <- make_tree(10,3)
g2 <- make_tree(30,3)

gs <- c(g1,g2)

as.igraph(gs[1])

但它不起作用。我收到错误:

Error in UseMethod("as.igraph") : 
  no applicable method for 'as.igraph' applied to an object of class "list"

您可以将它们存储在列表中:

gs <- list(g1,g2)
class(gs[[1]])
# [1] "igraph"

gs[[i]] 是 igraph,您不需要对它们 运行 as.igraph

此外,根据文档,as.igraph 函数只能用于 codeigraphHRG 个对象。