【发布时间】:2020-04-06 23:18:30
【问题描述】:
我需要使用 igraph 包读出 R 中最短路径序列的顶点名称。
library(igraph)
links = dplyr::tribble(~from, ~to, ~weight,
1,5,4,
3,4,5,
7,1,1,
3,7,3,
4,3,2,
6,5,7,
2,8,3,
5,2,9,
7,6,5)
net = graph_from_data_frame(links, directed = TRUE)
plot(net)
sp = shortest_paths(net, from = "3", to = "8", mode = "out", weights = get.edge.attribute(net, "weight"))
sp$vpath
现在我得到的是序列:3 7 1 5 2 8 作为具有内部 id (2 3 1 7 6 8) 的向量的名称
我如何获得顶点名称的简单未命名整数向量,因为我在 tribble 函数中定义它们并且它们也显示在图中。
我想这是一个非常简单的问题,但还是感谢你帮助我!
【问题讨论】:
-
我不知道这样做的首选方法,但似乎你可以这样做
names(sp$vpath[[1]])
标签: r igraph nested-lists shortest-path