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
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.
get.edgelist(g)
is the one you want, which spits out a matrix like:
# [,1] [,2]
#[1,] 3 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With