I have a directed graph, G. Some of the edges in G are reciprocal, and some are not. For reciprocal edges, edge attributes may be different. That is E(v1,v2)$att may not equal E(v2,v1)$att.
I need to fill in all missing reciprocal edges (that is, if E(v2,v1) does not exist while E(v1,v2) does, I want to create E(v2, v1) and copy all attribute information from E(v1, v2)).
If the reciprocal edge does exist, I need to keep the unique edge attribute information.
There are a lot of edges and a lot of attributes, so I am trying to avoid a loop here. Currently, where g1 is the directed but incomplete graph, I:
#make undirected with loops for reciprocal friendships
g2 <- as.undirected(g1, mode = c("each"))
#force everything to be directed, create new edges
g <- as.directed(g2, mode = c("mutual"))
#get rid of the double loops.
gnew <- simplify(g, remove.multiple = TRUE,
edge.attr.comb = "random")
The only problem with this is edge.attr.comb = "random" That is, I override the pre-existing mutual edge attribute information. I am thinking that I can flag missing mutual edges from g1and add the necessary edges (and copy their attribute information) using which_mutual but am having a difficult time with the indexing of edges. I must be missing an easy solution. An example:
g <- graph_from_literal(A+-+B, A-+C)
E(g)$att1 <- c(1,2,3)
#I want (note the default order of vertices for igraph)
g2 <- graph_from_literal(A+-+B, A+-+C)
E(g2)$att1 <- c(1, 2, 3, 2)