Search code examples
rigraph

igraph get edge from - to value


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


Solution

  • 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.