按顶点名称排列的边序列
好吧,我正在使用 igraph 包,在一个小例子中,我想通过分配给顶点的名称来选择边。
library(igraph)
g <- barabasi.game(8)
labels<-c("G1","G2","G3","T1","T2","T3","H1","H2")
V(g)$name<-labels
现在我的边列表已经这种形式
> E(g)
Edge sequence:
[0] G2 -> G1
[1] G3 -> G2
[2] T1 -> G2
[3] T2 -> G3
[4] T3 -> G1
[5] H1 -> G1
[6] H2 -> H1
我现在想要的是找到一种方法,而不是使用它
E(g)[1%--%2]
做更像 E(g)[G2%--%G1] (通过我指定的名称调用顶点)或等效的方式通过所涉及顶点的名称了解一些边属性。
Well, I'm working with the igraph
package, and I'd like to pick the edges by the name that I've assigned to their vertex, in a tiny example..
library(igraph)
g <- barabasi.game(8)
labels<-c("G1","G2","G3","T1","T2","T3","H1","H2")
V(g)$name<-labels
Now My edge list hast this form
> E(g)
Edge sequence:
[0] G2 -> G1
[1] G3 -> G2
[2] T1 -> G2
[3] T2 -> G3
[4] T3 -> G1
[5] H1 -> G1
[6] H2 -> H1
What i want now is to find a way of, instead of using this
E(g)[1%--%2]
doing something more like E(g)[G2%--%G1] (calling the vertex by the name i've assigned), or an equivalent way of knowing some edges attributes by the name of the vertex involved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将顶点名称括在引号中。这提供了与使用顶点编号相同的输出。这适用于 igraph 0.7.1。
例如:
Enclose the vertex names in quotes. This gives identical output to using the vertex number. This works in igraph 0.7.1.
For example:
这对于 igraph 的 0.5 分支来说是不可能的,但开发版本 (0.6) 添加了对基于顶点的
name
属性而不是数字 ID 引用顶点的支持。我不知道如何做到这一点,因为我不熟悉 R 界面。尝试订阅 igraph-help 邮件列表 并在那里询问,因为这绝对是已经发生过的事情最近在 igraph 0.6 中解决了。This is not possible with the 0.5 branch of igraph, but the development version (0.6) adds support for referring to vertices based on their
name
attribute instead of their numeric IDs. I'm not sure how to do that as I am not familiar with the R interface. Try to subscribe to the igraph-help mailing list and ask there as this is definitely something that has been solved recently in igraph 0.6.