如何访问 get.shortest.paths 的 'epath' 输出以获取边名称?
How can I access the 'epath' output of get.shortest.paths to get the edge names?
我想访问 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')
我可以访问顶点的名称:
names(unlist(solid.vpaths$vpath[4]))
但是我无法访问边的名称,它只是出现空值:
names(unlist(solid.epaths$epath[4]))
如果您有其他方法,我愿意接受建议。最后,我基本上需要一个边名称的字符向量。
谢谢!
给他们起名字得到名字:
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)
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"
我想访问 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')
我可以访问顶点的名称:
names(unlist(solid.vpaths$vpath[4]))
但是我无法访问边的名称,它只是出现空值:
names(unlist(solid.epaths$epath[4]))
如果您有其他方法,我愿意接受建议。最后,我基本上需要一个边名称的字符向量。
谢谢!
给他们起名字得到名字:
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)
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"