【问题标题】:Get vertex ids from igraph::shortest_path output - R从 igraph::shortest_path 输出获取顶点 ID - R
【发布时间】: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


【解决方案1】:

答案是:

名称(sp$vpath[[1]])

谢谢“user20650”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 2013-12-19
    • 2018-04-14
    • 2015-11-20
    • 1970-01-01
    相关资源
    最近更新 更多