从 igraph::shortest_path 输出中获取顶点 ID - R

Get vertex ids from igraph::shortest_path output - R

我需要使用 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]])

谢谢"user20650"