title: Populating a data frame in R in a loop
body: <p>I am trying to populate a data frame from within a for loop in R. The names of the columns are generated dynamically within the loop and the value of some of the loop variables is used as the values while populating the data frame. For instance the name of the current column could be some variable name as a string in the loop, and the column can take the value of the current iterator as its value in the data frame.</p>
  
  <p>I tried to create an empty data frame outside the loop, like this</p>
  
  <pre><code>d = data.frame()
  </code></pre>
  
  <p>But I cant really do anything with it, the moment I try to populate it, I run into an error</p>
  
  <pre><code> d[1] = c(1,2)
  Error in `[&lt;-.data.frame`(`*tmp*`, 1, value = c(1, 2)) : 
    replacement has 2 rows, data has 0
  </code></pre>
  
  <p>What may be a good way to achieve what I am looking to do. Please let me know if I wasnt clear.</p>