子集igraph对象到某些顶点的2阶自我图 [英] subset igraph object to just 2nd order ego graph of certain vertices
本文介绍了子集igraph对象到某些顶点的2阶自我图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
构建此处的问题 ,是否有一种方法可以扩展此子图,使其包括以两个角度连接到顶点子集的顶点?我正在考虑一个类似于make_ego_graph()中的功能的命令,其中order = 2和mode ="in".我正在使用有向图对象.
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!
推荐答案
这不是最优雅的解决方案,但它似乎可以工作.
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)
}
这篇关于子集igraph对象到某些顶点的2阶自我图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文