在R中使用igraph找到另一个图形中遗漏的一个图形中的唯一边

时间:2016-03-30 10:58:42

标签: r igraph

我创造了两个带有以下边缘的无向igraph

graph1 => A--AA--BA--C

graph2 => B--AC--DD--EA--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)

我想找到graph2独有的边缘。因此,输出应该是:

# C--D D--E

1 个答案:

答案 0 :(得分:1)

你可以尝试

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

或者,关于您的编辑:

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