title: Graph.union summing edge weights attributes (igraph R)
body: <p>I have 2 graphs, with weight labels:</p>
  
  <pre><code>library(igraph)
  
  g1= graph.formula(A -+ B, A -+ C)
  E(g1)["A" %-&gt;% "B"]$weight= 1
  E(g1)["A" %-&gt;% "C"]$weight= 2
  E(g1)$label= E(g1)$weight
  
  g2= graph.formula(A -+ B, A -+ C, A -+ D)
  E(g2)["A" %-&gt;% "B"]$weight= 10
  E(g2)["A" %-&gt;% "C"]$weight= 20
  E(g2)["A" %-&gt;% "D"]$weight= 100
  E(g2)$label= E(g2)$weight
  
  par(mfrow= c(2,1), mar= rep(0,4))
  plot(g1); plot(g2)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/HPCNq.png" alt="enter image description here"></p>
  
  <p>When joining both with <code>graph.union()</code>, <code>igraph</code> by default creates <code>weight_1, weight_2</code> attributes. </p>
  
  <p><strong>Problem:</strong></p>
  
  <p>I want the joined graph to have edge weight attributes summed up. Applying existing <a href="https://stackoverflow.com/questions/27762359/combine-two-graphs-and-add-edge-weights-in-r-igraph">SO answer</a> is not optimal. 
  First the solution does not scale well in case <code>graph.union()</code> creates many more <code>weight_...</code> attributes. Second it leads in case of the reproducible example only to a partial solution, as the edge <code>"A" "D"</code> contains no sum.</p>
  
  <pre><code>g= graph.union(g1, g2)
  E(g)$weight= E(g)$weight_1 + E(g)$weight_2
  E(g)$label= E(g)$weight
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/MoCPX.png" alt="enter image description here"></p>
  
  <p><strong>Question:</strong></p>
  
  <p>How can I recode to get finally following graph:</p>
  
  <p><img src="https://i.stack.imgur.com/wkceU.png" alt="enter image description here"></p>
  
  <p>Comment: I am not looking for a manual solution (<code>E(g)["A" %-&gt;% "D"]$label= 100</code>), as I am handling lots of edges.</p>