在R中使用igraph找到另一个图中缺少的一个图中的唯一边(Using igraph in R find unique edges in one graph missing from another

编程入门 行业动态 更新时间:2024-10-24 18:20:37
在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--E

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

最满意答案

你可以试试

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

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

更多推荐

本文发布于:2023-07-14 20:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图中   find   igraph   unique   missing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!