如何访问get.shortest.paths的"epath"输出以获取边缘名称? [英] How can I access the 'epath' output of get.shortest.paths to get the edge names?

查看:73
本文介绍了如何访问get.shortest.paths的"epath"输出以获取边缘名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to access the 'epath' output of the get.shortest.paths and get the names of the edges, rather than the ID's. At the moment, I have the edge ID's, but I need the names of the edges. For example:

# 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]))

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

But I cannot access the names of the edges, it just comes up null:

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

如果您有其他方法,欢迎提出建议.最后,我基本上需要边缘名称的字符向量.

If you have another method I'm open to suggestions. In the end, I basically need a character vector of the edge names.

谢谢!

推荐答案

为他们提供名称以获取名称:

Give them names to get names:

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"输出以获取边缘名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆