r - 在 igraph R 中查找没有任何前趋/传入边的顶点

标签 r igraph graph-databases

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

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 没有任何前驱。有没有查询函数可以轻松获取这样的顶点?

最佳答案

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

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"

关于r - 在 igraph R 中查找没有任何前趋/传入边的顶点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36102345/

相关文章:

r - 填充数据框中缺少的组合

r - 向ggplot2图形添加多个阴影/矩形

java - Titan DB 中的顶点 ID 更新

java - 如何部署非托管插件并从 Maven 重新启动 Neo4j 服务器?

r - 在 Quantmod R 中添加多个图表系列

python - 是否可以更正我在 R 中对 paste0() 的使用,以便该函数运行得与原始 Python 示例一样快?

r - 顶点大小取决于中介中心性的 igraph 绘图图

Python igraph 顶点索引

r - 如何在 igraph 中对社区集群内的边缘进行着色

sql - Orientdb SQL 查询检查边缘属性