subset igraph object to just 2nd order ego graph of certain vertices

杀马特。学长 韩版系。学妹 提交于 2019-12-12 05:27:58

问题


Building off this question here, is there a way to extend this subgraph to include vertices connected by two degrees to a subset of vertices? I'm thinking of a command similar to the functions in make_ego_graph() where order=2 and mode="in". I'm working with a directed graph object.

Thus far, I've come up with the following, but it's not producing the graph I'm looking for.

first_degree <- V(graph)$condition == "something"
second_degree <- V(graph)[to(first_degree)]
edges_subset <- E(graph)[to(first_degree) | to(second_degree)]
desired_subset <- subgraph.edges(graph, edges_subset)

Thanks for any advice you can give me!


回答1:


It's not the most elegant solution, but it seems to work.

 ego.list <- make_ego_graph(graph, order=2, nodes=V(graph)$condition=="something")

   desired_subset <- NULL
   for (i in seq_along(ego.list)){
   x <- ego.list[[i]]
   desired_subset <- graph.union(desired_subset, x)
}


来源:https://stackoverflow.com/questions/44712041/subset-igraph-object-to-just-2nd-order-ego-graph-of-certain-vertices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!