title: Data frames with mixed data types
body: <p>I have been using R for a little while, but I am still struggling with factors and data frames.
  Here's my question.</p>
  
  <p>I am trying to pre-allocate a data frame composed of several columns of different types, as follows:</p>
  
  <pre><code>cb &lt;- data.frame(S=character(1000), I=numeric(1000), A=as.Date(rep(0,1000), origin = "1900-01-01"), SD=as.POSIXct(rep(0,1000), origin = "1900-01-01 00:00:00"), CC=numeric(1000), stringsAsFactors=FALSE)
  </code></pre>
  
  <p>which gets met the data frame types that I want (output of str(cb)):</p>
  
  <pre><code>'data.frame':   1000 obs. of  5 variables:
   $ S : chr  "" "" "" "" ...
   $ I : num  0 0 0 0 0 0 0 0 0 0 ...
   $ A : Date, format: "1900-01-01" "1900-01-01" "1900-01-01" "1900-01-01" ...
   $ SD: POSIXct, format: "1900-01-01" "1900-01-01" "1900-01-01" "1900-01-01" ...
   $ CC: num  0 0 0 0 0 0 0 0 0 0 ...
  </code></pre>
  
  <p>When I assign the first item in the data frame, CC and I become characters:</p>
  
  <pre><code>cb[1, ] &lt;- c("ABCD", 4, "2005-12-12", "2008-04-03 20:30", 3)
  </code></pre>
  
  <p>output of str(cb):</p>
  
  <pre><code>'data.frame':   1000 obs. of  5 variables:
   $ S : chr  "ABCD" "" "" "" ...
   $ I : chr  "4" "0" "0" "0" ...
   $ A : Date, format: "2005-12-12" "1900-01-01" "1900-01-01" "1900-01-01" ...
   $ SD: POSIXct, format: "2008-04-03 20:30:00" "1900-01-01 00:00:00" "1900-01-01 00:00:00" "1900-01-01 00:00:00" ...
   $ CC: chr  "3" "0" "0" "0" ...
  </code></pre>
  
  <p>which makes it rather unusable for my purposes.</p>
  
  <p>When I omit stringsAsFactors=FALSE in the data.frame definition, I (obviously) get a different error message (having set warn to 2):</p>
  
  <pre><code>Error in `[&lt;-.factor`(`*tmp*`, iseq, value = "ABCD") : 
    (converted from warning) invalid factor level, NAs generated
  </code></pre>
  
  <p>which I understand but I am not sure how to overcome either.</p>
  
  <p>What am I doing wrong? How can I make sure to keep the numeric type for columns I and SD?
  Thanks so much for your help.</p>
  
  <p>Cheers</p>
  
  <p>B</p>