2016-01-06 32 views
4

是否可以將一組圖形(從igraph)存儲在向量或其他數據結構中?如何在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" 

回答

2

您可以將它們存儲在一個列表:

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

gs[[i]]是igraphs,你不需要在它上面運行as.igraph

此外,根據文檔,as.igraph函數只能用於codeigraphHRG對象。