如何访问get.shortest.paths的'epath'输出以获取边缘名称?

时间:2016-10-04 17:29:11

标签: r igraph

我想访问get.shortest.paths的'epath'输出并获取边的名称,而不是ID的名称。目前,我有边缘ID,但我需要边缘的名称。例如:

# create graph
solid = graph_from_literal(A-D,A-C,D-F,D-C,C-B,B-E)

# get edges of shortest paths
solid.epaths = get.shortest.paths(solid, from = 1, to = V(solid),output = 'epath')

# get verticies of shortest paths
solid.vpaths = get.shortest.paths(solid, from = 1, to = V(solid),output = 'vpath')

我可以访问verticies的名称:

names(unlist(solid.vpaths$vpath[4]))

但是我无法访问边缘的名称,它只是出现了null:

names(unlist(solid.epaths$epath[4]))

如果您有其他方法,我愿意接受建议。最后,我基本上需要一个边缘名称的字符向量。

谢谢!

1 个答案:

答案 0 :(得分:0)

给他们起名字来获取名字:

library(igraph)
solid = graph_from_literal(A-D,A-C,D-F,D-C,C-B,B-E)
E(solid)$name <- letters[seq_len(ecount(solid))]
plot(solid, edge.label = E(solid)$name)

enter image description here

solid.epaths = get.shortest.paths(solid, from = 1, to = 4, output = 'epath')
solid.vpaths = get.shortest.paths(solid, from = 1, to = 4, output = 'vpath')

names(unlist(solid.vpaths$vpath))
# [1] "A" "D" "F"
names(unlist(solid.epaths$epath))
# [1] "a" "d"