在R中使用igraph找到另一个图中缺少的一个图中的唯一边(Using igraph in R find unique edges in one graph missing from another graph)
我创建了两个带有以下边缘的无向igraph
graph1 => A--A , A--B和A--C
graph2 => B--A , C--D , D--E和A--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--EI 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最满意答案
你可以试试
get.edgelist(graph2-graph1) # [,1] [,2] # [1,] "C" "D" # [2,] "D" "E"或者,关于您的编辑:
E(graph2-graph1) # + 2/2 edges (vertex names): # [1] C--D D--EYou 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更多推荐
发布评论