小编Mic*_*ner的帖子

Tidygraph: obtain sequence of nodes along shortest path

I would like to obtain the sequence of nodes along the shortest path between two nodes using tidygraph. Consider this example.

library(tidygraph)
library(tidyverse)
demo_netw <- tbl_graph(nodes = tibble(node_id = c("A", "B", "C", "D")),
                       edges = tribble(~from, ~to,
                                       "B", "A",
                                       "D", "C",
                                       "A", "D"))
shortest_path_from_B_to_C <-
  demo_netw %>%
  convert(to_shortest_path, node_id == "B", node_id == "C")
shortest_path_from_B_to_C

## # A tbl_graph: 4 nodes and 3 edges
## #
## # A rooted tree
## #
## # Node Data: 4 x 2 …
Run Code Online (Sandbox Code Playgroud)

r igraph tidyverse tidygraph

4
推荐指数
1
解决办法
798
查看次数

标签 统计

igraph ×1

r ×1

tidygraph ×1

tidyverse ×1