开发者

edge sequence by vertex name

开发者 https://www.devze.com 2023-01-15 22:41 出处:网络
Well, I\'m working with the igraph package, and I\'d like to pick the edge开发者_运维知识库s by the name that I\'ve assigned to their vertex, in a tiny example..

Well, I'm working with the igraph package, and I'd like to pick the edge开发者_运维知识库s 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.


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.


Enclose the vertex names in quotes. This gives identical output to using the vertex number. This works in igraph 0.7.1.

For example:

> E(g)[1%--%8]
Edge sequence:
    e         
e [7] H2 -> G1

> E(g)['H2'%--%'G1']
Edge sequence:
    e         
e [7] H2 -> G1
0

精彩评论

暂无评论...
验证码 换一张
取 消