graph.intersection
gives a graph that contains exactly the common edges:
library(igraph)
set.seed(42 * 42)
g1 <- erdos.renyi.game(5, 0.8)
g2 <- erdos.renyi.game(5, 0.5)
g1[]
# 5 x 5 sparse Matrix of class "dgCMatrix"
#
# [1,] . 1 1 1 1
# [2,] 1 . 1 1 .
# [3,] 1 1 . 1 1
# [4,] 1 1 1 . 1
# [5,] 1 . 1 1 .
g2[]
# 5 x 5 sparse Matrix of class "dgCMatrix"
#
# [1,] . . 1 1 .
# [2,] . . . 1 .
# [3,] 1 . . 1 1
# [4,] 1 1 1 . .
# [5,] . . 1 . .
gi <- graph.intersection(g1, g2)
gi[]
# 5 x 5 sparse Matrix of class "dgCMatrix"
#
# [1,] . . 1 1 .
# [2,] . . . 1 .
# [3,] 1 . . 1 1
# [4,] 1 1 1 . .
# [5,] . . 1 . .
ecount(gi)
# [1] 5