title: Add Columns to an empty data frame in R
body: <p>I have searched extensively but not found an answer to this question on Stack Overflow.</p>
  
  <p>Lets say I have a data frame a.</p>
  
  <p>I define:</p>
  
  <pre><code>a &lt;- NULL
  a &lt;- as.data.frame(a)
  </code></pre>
  
  <p>If I wanted to add a column to this data frame as so:</p>
  
  <pre><code>a$col1 &lt;- c(1,2,3)
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Error in `$&lt;-.data.frame`(`*tmp*`, "a", value = c(1, 2, 3)) : 
      replacement has 3 rows, data has 0
  </code></pre>
  
  <p>Why is the row dimension fixed but the column is not?</p>
  
  <p>How do I change the number of rows in a data frame?</p>
  
  <p>If I do this (inputting the data into a list first and then converting to a df), it works fine:</p>
  
  <pre><code>a &lt;- NULL
  a$col1 &lt;- c(1,2,3)
  a &lt;- as.data.frame(a)
  </code></pre>