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

Is it possible to store a set of graphs (from igraph) in a vector or other data structure?

I am trying to do it like this:

require('igraph')

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

gs <- c(g1,g2)

as.igraph(gs[1])

but that will not work. I got an error:

Error in UseMethod("as.igraph") : 
  no applicable method for 'as.igraph' applied to an object of class "list"
+4
source share
1 answer

You can save them in the list:

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

gs[[i]]are igraphs and you do not need to run as.igraphon them.

In addition, according to the documents, the function as.igraphcan only be used for objects codeigraphHRG.

+2
source

Source: https://habr.com/ru/post/1623080/


All Articles