title: How can I add rows to a data frame inside a loop without forcing all columns to be the same type?
body: <p>Let's say I want to make a data frame with a numeric column and a character column:</p>
  
  <pre><code>df&lt;-data.frame()
  for(i in 1:26) {
    df&lt;-rbind(df, cbind(x=i, y=toString(i)))
   }
  str(df)
  'data.frame':   26 obs. of  2 variables:
   $ x: Factor w/ 26 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
    ..- attr(*, "names")= chr  "x" "x" "x" "x" ...
   $ y: Factor w/ 26 levels "1","2","3","4",..: 1 2 3 4 5 6 7 8 9 10 ...
    ..- attr(*, "names")= chr  "y" "y" "y" "y" ...
  </code></pre>
  
  <p>Oops, I didn't want factors.</p>
  
  <pre><code>df2&lt;-data.frame()
  for(i in 1:26) {
     df2&lt;-rbind(df2, cbind(x=i, y=toString(i)), stringsAsFactors=FALSE)
    }
  str(df2)
  'data.frame':   26 obs. of  2 variables:
   $ x: chr  "1" "2" "3" "4" ...
   $ y: chr  "1" "2" "3" "4" ...
  </code></pre>
  
  <p>Now everything is a character. The only way I can figure out to avoid this is by constructing separate vectors and then forming the data frame at the end:</p>
  
  <pre><code>x&lt;-NULL
  y&lt;-NULL
  for(i in 1:26) {
    x&lt;-c(x, i)
    y&lt;-c(y, toString(i))
   }
  df3&lt;-data.frame(x, y, stringsAsFactors=FALSE)
  str(df3)
  'data.frame':   26 obs. of  2 variables:
   $ x: int  1 2 3 4 5 6 7 8 9 10 ...
   $ y: chr  "1" "2" "3" "4" ...
  </code></pre>
  
  <p>But as you can see, this requires extra code. If you have a data frame with 20 columns, you need 20 initialization statements before the loop and 20 statements inside the loop to add to the vectors.</p>
  
  <p>Is there a more concise way of accomplishing this?</p>