首页 > 解决方案 > 如何将大量 igraph 组合成一个 igraph - R

问题描述

我有一个需要过滤的大图。过滤(子图)后,我最终得到一个子图列表。我需要再次将所有这些子图组合成一个图。我不知道如何组合大列表(近一百万个子图)

> require(igraph)
> graph <- make_ring(7)  #this is my original graph
> V(graph)$name <- c("A", "B", "C", "D", "E", "F", "G")  #name of vertices
> V(graph)$att1 <- c(1,2,NA,1,2,3,NA)  #some attribute
> selected_vertices <- V(graph)$name[which(V(graph)$att1 == 1)] #let's say i need to subgraph the graph to include only vertices with att1 == 1 (and their first order neighbours)
> subgraph_list <- make_ego_graph(graph, order=1, selected_vertices)  #this creates a list of igraphs but I need one graph containing all the graphs

这失败了:

> subgraph <- induced_subgraph(graph, unlist(subgraph_list ))
Error in as.igraph.vs(graph, vids) : 
  (list) object cannot be coerced to type 'double'

我尝试了其他方法来对图进行自我子图化,但由于它是一个相当大的图,因此需要很长时间,而且运行良好且相对较快的一个函数是 make_ego_graph,它创建了一个列表。

标签: rlistigraphsubgraph

解决方案


我假设你想要这些图的联合:

do.call(union, subgraph_list)

推荐阅读