title: Save loop results as csv table
body: <p>I have simple loop that generate a value at each step, and I want to save all results as a single table. Problem is that each step overwrites the previous.</p>
  
  <pre><code>for(i in 1:5){
    x = 3*i
    print(c(i,x))
  }
  </code></pre>
  
  <p>This gives </p>
  
  <pre><code>  [1] 1 3
    [1] 2 6
    [1] 3 9
    [1] 4 12
    [1] 5 15
  </code></pre>
  
  <p>Now I create a matrix that I will then save as a csv file, but it only shows the final step of the loop.</p>
  
  <pre><code>results = matrix(c(i,x), ncol = 2)
       [,1] [,2]
  [1,]    5   15
  
  write.table(results, file = "Results.csv", col.names=NA, append = T)
  </code></pre>
  
  <p>How to show the entire list of results? Thanks in advance!</p>
  
  <p>(ps.- I know that a similar question has been posted previously, e.g. <a href="https://stackoverflow.com/questions/11292880/write-output-of-r-loop-to-file">Write output of R loop to file</a>, but the problem was quite specific and I did not manage to adapt the answers to my case).</p>