title: I want to assign and store a new value for each iteration in a for loop
body: <p>I want to assign and store a new value into the R environment for each iteration of a for loop as said in the title. </p>
  
  <pre><code>csg&lt;-clusters(suba)
  
  csgs1&lt;-subgraph(suba, csg$membership==1)
  
  sg1&lt;-cluster_spinglass(csgs, weights=E(a)$weight)
  </code></pre>
  
  <p>So, given some igraph object (suba), I want to create sg1, sg2,..., sg31. I don't want to go through the 2 lines of code above 31 times though so I've tried a for loop? But I don't know how to store a new value each time. </p>
  
  <pre><code>for (k in 1:seq_along(length(csg$csize))){
  
    csgs[k] &lt;- subgraph(suba, csg$membership==k)
  
    sg [k] &lt;-cluster_spinglass(csgs[k] , weights=E(a)$weight)
  
    }
  </code></pre>
  
  <p>Obviously, the square brackets don't work in this situation but I couldn't find how to do this.</p>
  
  <p>Ideally, I'd want to have sg1,sg2, etc saved into the R environment so that I could use these as the groups for my network suba. Because my code is straight up not working, I don't get results at the moment. It works individually though, creating a subgraph for csgs1 and a list for sg1.</p>