Identify number of same/different edges between two igraph objects r
<p>I have these 3 igraph objects:</p>

<pre><code>g1 &lt;- graph( edges=c(1, 2, 2, 3, 3, 1), n=3, directed=T ) 
g2 &lt;- graph( edges=c(1, 2, 2, 3, 1, 3), n=3, directed=T ) 
g3 &lt;- graph( edges=c(1, 2, 2, 3, 1, 3, 3, 4), n=4, directed=T ) 


IGRAPH D--- 3 3 -- 
+ edges:
[1] 1-&gt;2 2-&gt;3 3-&gt;1

IGRAPH D--- 3 3 -- 
+ edges:
[1] 1-&gt;2 2-&gt;3 1-&gt;3

IGRAPH D--- 4 4 -- 
+ edges:
[1] 1-&gt;2 2-&gt;3 1-&gt;3 3-&gt;4
</code></pre>

<p>I want to compare the edges of g1 to g2 and of g2 to g3.  I want to count the number of edges that are exactly the same, the number of edges that are reversed (e.g. 1->3 changes to 3->1), and the number of additional edges.</p>

<p>Is there a simple function for doing this sort of comparison of edges?</p>

<p>How I do it currently is to get the edgelist and then do some row matching method to compare what exists and doesn't:</p>

<pre><code>igraph::get.edgelist(g1) 
igraph::get.edgelist(g2) 
igraph::get.edgelist(g3)



&gt; igraph::get.edgelist(g1)
     [,1] [,2]
[1,]    1    2
[2,]    2    3
[3,]    3    1
&gt; igraph::get.edgelist(g2)
     [,1] [,2]
[1,]    1    2
[2,]    2    3
[3,]    1    3
&gt; igraph::get.edgelist(g3)
     [,1] [,2]
[1,]    1    2
[2,]    2    3
[3,]    1    3
[4,]    3    4
</code></pre>

<p>However, this seems long-winded. Is there a simpler way to compare two igraph objects?</p>

<p>The output for g1 to g2 would be: </p>

<pre><code>same  reverse  addition
   2        1         0
</code></pre>

<p>and for g2 to g3 would be:</p>

<pre><code>same  reverse  addition
   3        0         1
</code></pre>