考虑这个简单的例子
library(tidygraph)
mynodes <- tibble(id = c(1,2,3,4,5))
myedges <- tibble(from = c(1,1,1,5),
to = c(1,2,3,4),
power = c(10,10,10,3))
tbl_graph(nodes = mynodes, edges = myedges)
# A tbl_graph: 5 nodes and 4 edges
#
# A directed multigraph with 2 components
#
# Node Data: 5 x 1 (active)
id
<dbl>
1 1
2 2
3 3
4 4
5 5
#
# Edge Data: 4 x 3
from to power
<int> <int> <dbl>
1 1 1 10
2 1 2 10
3 1 3 10
# ? with 1 more row
我知道我可以filter
用来轻松过滤节点或边缘。
我的问题是如何根据边缘上的条件过滤节点。
例如运行:
mygraph %>% activate(edges) %>% filter(power == 3)
仍然会返回所有节点,这在绘图时很烦人(这些节点将没有边!)。
如何保留与过滤后的边集连接的所有节点?
# A tbl_graph: 5 nodes and 1 edges
#
# A rooted forest with 4 trees
#
# Edge Data: 1 x 3 (active)
from to power
<int> <int> <dbl>
1 5 4 3
#
# Node Data: 5 x 1
id
<dbl>
1 1
2 2
3 3
# ? with 2 more rows