A vertex sequence by igraph seems not be a sequence. For example:
The v sequence by V( module.net )
is a sequence, since I can access it by [deg==1]
. But why it does't work when I try peripheral[1]
? Any possible explanation for this?
The dataset for this example is not easy to be included, sorry for that.
//
I find the answer, the index of first vertex 'MED24' is 4, instead of 1. So if I want to get the first vertex, I have to do peripheral[1]
. But this seems a little unreasonable. A replicatable example:
g = graph.ring(5)
V(g)$name = c('node1', 'node2', 'node3','node4','node5')
temp = V(g)[2:3]
If you want to access 'node3' from temp, you have to use temp[3]
instead of temp[2]
I've always had trouble with vertex sequences and edge sequences. The problem with the indexing operator on those objects is that is searched by vector name, not position. So peripheral[1]
is looking to see if vector 1 is in the list, it's not extracting the first element in the list.
The best i've come up with is converting the sequence to a simple vector and re-indexing the vector list. For example
el <- cbind(letters[1:5], letters[c(2,3,5,1,4)])
gg <- graph.edgelist(el)
p <- V(gg)[c(2,3)]
V(gg)[as.vector(p)[1]]
Actually, if you just want to extract the name of a particular vertex, then
p$name[1]
would work.