Rigograph祖先python [英] R igraph ancestors python

查看:86
本文介绍了Rigograph祖先python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网络,如图所示.在python中有祖先函数.当我在节点5上使用它时,它将提供节点1,2和3的列表.igraph R中的等效功能是什么?我尝试了子组件,但对我而言不起作用.

I have a network like in the diagram. In python there is the ancestors function. When i use it on node 5, it will provide list of nodes 1,2 and 3. what is an equivalent function in igraph R? I tried subcomponent but it didn't work for me.

我的实际网络也很安静,我不想使用父子功能,因为我不知道每种情况的程度

Also my actual network is quiet long and I don't want to use parent or child function as I don't know degree in every case

推荐答案

R函数是neighborhoodmode="in": http://igraph.org/r/doc/neighborhood.html 例如

g1 <- graph(c(1,4, 1,2, 1,3, 3,2, 2,5))
neighborhood(g1, 5, order=vcount(g1), mode="in")[[1]]
# [1] 5 2 1 3

这还将包括查询的顶点本身,但是很容易删除它:

This will also include the queried vertex itself, but it is easy to remove that:

setdiff(neighborhood(g1, 5, order=vcount(g1), mode="in")[[1]], 5)
# [1] 2 1 3

这篇关于Rigograph祖先python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆