繁体   English   中英

在igraph R中找到没有任何前驱/进入边的顶点

[英]Find vertices without any predecessor/ingoing edges in igraph R

如何在图中获得没有任何前驱的顶点。 例如,这是图表数据:

lfs = data.table( from = c('x', 'x', 'y'), to = c('y', 'p', 'z'))
lfs
#  from to
#:    x  y
#:    x  p
#:    y  z
g = graph_from_data_frame(lfs)
g
# IGRAPH DN-- 4 3 --
# + attr: name (v/c)
# + edges (vertex names):
# [1] x->y x->p y->z

在此图中, x没有任何前身。 是否有任何查询功能可以轻松获得这些顶点?

您可以使用degree来查找进入节点的边

library(igraph)
lfs <- data.frame( from = c('x', 'x', 'y'), to = c('y', 'p', 'z'))    
g <- graph_from_data_frame(lfs)

# find the edges in to a node
degree(g, mode="in")
#x y p z 
#0 1 1 1

# You can then subset to get the node names
V(g)$name[!degree(g, mode="in")]
# "x"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM