title: Output from loops
body: <p>I wish to write the output from each loop iteration to a separate <code>.csv</code> file <strong>or</strong> add each loop as a new row in a separate object, which can them be output as a <code>.csv</code>, sequentially.   </p>
  
  <p>I've tried using <code>write.csv</code> but I am unsure how to apply it in the loop whereby a new file is created for each <code>i</code>.</p>
  
  <pre><code>for (i in seq(1,1128,12)){
    Array &lt;- ncvar_get(temp_cont, varid = "TREFHT", start = c(1,1,1,i), count= c(144,96,60,12))
    myArray &lt;- array(Array, dim =c(144, 96, 60, 12))
    Annual &lt;- apply(myArray, c(1,2,3), mean)    
    myArray2 &lt;- array(Annual, dim = c(144,96,60))
    Annuallat &lt;- apply(myArray2, c(2,3), mean)  
    myArray3 &lt;- array(Annuallat, dim = c(96,60))
    AnnualGLobal &lt;- apply(myArray3, 2,mean)    
    AnnualGlobalc &lt;- AnnualGLobal - 273.15  
    write.csv(AnnualGlobalc, file = "year[i].csv")   
  }
  </code></pre>