title: Assigning edge weight to an igraph object in R
body: <p>I have a co-occurrence matrix that I want to convert to an igraph object. The matrix has three columns- <code>node1</code>, <code>node2</code> and <code>freq</code>.</p>
  
  <p>I have created the graph using the <code>graph_from_edgelist</code> command.</p>
  
  <pre><code>g &lt;- graph_from_edgelist(as.matrix(coOccurDf[1:n,1:2]), directed=F)
  </code></pre>
  
  <p>I now need to assign weights to the edges. I've tried to use two functions, which both seem to do the same job, but to no avail.</p>
  
  <pre><code>set.edge.attribute(g, "weight", index=E(g), coOccurDf[1:n,]$freq)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>set_edge_attr(g, "weight", index=E(g), coOccurDf[1:n,]$freq)
  </code></pre>
  
  <p>Neither of these two commands throws an error, but when I try to see the weights using</p>
  
  <pre><code>E(g)$weight
  </code></pre>
  
  <p>It just displays <code>NULL</code>.</p>
  
  <p>Any help would be appreciated.</p>