Oshan
Oshan

Reputation: 176

Using igraph in R find unique edges in one graph missing from another graph

I have created two undirected igraph with the following edges

graph1 => A--A,A--BandA--C

graph2 => B--A,C--D,D--EandA--C

library(igraph)
my_data = data.frame(id1=c("A","A","A","B","C","A","D"),id2=c("A","B","C","A","D","C","E"))
graph1 = graph.data.frame(my_data[1:3,],directed=F)
graph2 = graph.data.frame(my_data[4:7,],directed=F)

I want to find edges unique to graph2. Therefore, the output should be like:

# C--D D--E

Upvotes: 0

Views: 328

Answers (1)

lukeA
lukeA

Reputation: 54237

You could try

get.edgelist(graph2-graph1)
#      [,1] [,2]
# [1,] "C"  "D" 
# [2,] "D"  "E" 

or, with regards to your edit:

E(graph2-graph1)
# + 2/2 edges (vertex names):
# [1] C--D D--E

Upvotes: 1

Related Questions