title: Aggregating weights of bidirectional edges in igraph while retaining edge attributes
body: <p>In a directed, weighted graph, when I have bidirectional edges, (I.e. <em>A-&gt;B</em> and <em>B-&gt;A</em> exist), I would like to subtract the two weights such that the resulting edge direction is in the direction of the larger weight. My example below accomplishes this for edges with only a 'weight' attribute, but when I have other edge attributes (multiple edges), I want to retain the attributes when aggregating. The issue with my example is that when I convert my graph to an adjacency matrix via <code>as_adjacency_matrix</code>, the function combines the weights and I lose the attribute data. How can I combine bidirectional edge weights while retaining edge attribute data?</p>
  <p><strong>Example with a &quot;group&quot; attribute:</strong></p>
  <pre><code>library(dplyr)
  library(igraph)
  library(visNetwork)
  
  df&lt;-data.frame(from = c('A','A','B','B','C','C','G','A','A','B','B','C','C','G'),
                 to = c('B','C','A','E','F','G','C','B','C','A','E','F','G','C'),
                 weight = c(50,30,20,15,45,34,60,40,100,20,25,35,72,50),
                 group = c('1','2','2','1','1','1','2','2','1','2','1','1','2','2'))
  
  g&lt;-igraph::graph_from_data_frame(df)
  
  # visual - original graph
  edges&lt;-igraph::as_data_frame(g, what = 'edges')
  nodes&lt;-data.frame(id = append(edges$from, edges$to) %&gt;% unique())
  visNetwork(nodes=nodes, edges = edges)%&gt;%
    visEdges(arrows =&quot;to&quot;)
  
  # aggregate bidirectional edges 
  g_old&lt;-g
  mx_old&lt;-as_adjacency_matrix(g_old, attr = &quot;weight&quot;) %&gt;% as.matrix()
  mx_new&lt;-mx_old
  
  u = mx_old[row(mx_old) == (col(mx_old) - 1)] # upper off-diagonal
  l = mx_old[row(mx_old) == (col(mx_old) + 1)] # lower off-diagonal
  
  mx_new[row(mx_new) == (col(mx_new) - 1)]&lt;-ifelse((u - l) &gt; 0, (u - l), ifelse((u - l) &lt; 0, 0, u))
  mx_new[row(mx_new) == (col(mx_new) + 1)]&lt;-ifelse((l - u) &gt; 0, (l - u), ifelse((l - u) &lt; 0, 0, l))
  
  # new graph with bidrectional edges removes
  g_new = graph_from_adjacency_matrix(mx_new, weighted = TRUE)
  
  # visual - new graph
  edges&lt;-igraph::as_data_frame(g_new, what = 'edges')
  nodes&lt;-data.frame(id = append(edges$from, edges$to) %&gt;% unique())
  visNetwork(nodes=nodes, edges = edges)%&gt;%
    visEdges(arrows =&quot;to&quot;)
  </code></pre>