Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

igraph get edge from - to value

Tags:

r

igraph

I have an igraph graph and want to simply get each edge's from_id and to_id. For example:

g <- erdos.renyi.game(4, 1, type="gnm", directed=FALSE)
E(g)[1] # will return some edge, possibly not the same one
# Edge sequence:
# e       
# e [1] 3 -- 1

What I want is to get two variables v1, v2 where v1 = 3 and v2 = 1 (equivalent to v1 = 1 and v2 = 3). I want to do this for all edges in the graph E(g)[x], where x is the loop variable. Is there any way to do this?

Thanks

like image 306
quine Avatar asked Jan 20 '14 20:01

quine


2 Answers

get.edges() returns all edges, get.edge() returns one edge. If you need to iterate over all edges, then call get.edges() and go over all lines of the two-column matrix, with apply(), or a for loop.

like image 168
Gabor Csardi Avatar answered Sep 20 '22 21:09

Gabor Csardi


get.edgelist(g) is the one you want, which spits out a matrix like:

#     [,1] [,2]
#[1,]    3    1
like image 45
thelatemail Avatar answered Sep 20 '22 21:09

thelatemail