I have a directed graph g. A pair of nodes can be connected by more that one edge. I need to leave only one edge. The edge's direction does not matter.

library(igraph)

g1 <- graph.formula( A ++ B ++ C, E ++ B ++ D, A -+ E, E -+ C, C -+ D, D -+ A )
par(mfrow=c(1,2))
plot(g1, edge.curved = TRUE)

The list of edges is:

edges <- as.data.frame(get.edgelist(g1));
edges <- edges[order(edges$V1, edges$V2), ]
edges 

#   V1 V2
#1   A  B
#2   A  E
#3   B  A # delete
#4   B  C # delete
#6   B  D # delete
#5   B  E # delete
#7   C  B
#8   C  D
#11  D  A
#12  D  B
#9   E  B
#10  E  C

My attempt is:

g2 <- delete_edges(g1, c("B|A", "B|E", "B|C", "B|D"))
plot(as.undirected(g2))

Question. How to automatizate the deletion process through a condition?

enter image description here

0 Answers