title: how to prevent dataframe columns being classed as character instead of numeric
body: <p>Good morning.</p>
  
  <p>I am cycling through some data, building a dataframe as I go.   Every time I add or replace a row in the dataframe, numeric values get classed as character, and I have to re-class them.  I assume I am doing something wrong when adding the data to the dataframe ?</p>
  
  <pre><code>test.df&lt;-data.frame(SIDE=rep("",5),n=rep(NA, 5),c1=rep(NA,5),stringsAsFactors=FALSE)
  test.df[1,]&lt;-cbind("A",1,256)
  test.df[2,]&lt;-cbind("A",2,258)
  test.df[3,]&lt;-cbind("A",3,350)
  test.df[4,]&lt;-cbind("A",4,400)
  test.df[5,]&lt;-cbind("A",5,360)
  summary(test.df)
   SIDE                n                  c1           
    Length:5           Length:5           Length:5          
    Class :character   Class :character   Class :character  
    Mode  :character   Mode  :character   Mode  :character  
  </code></pre>
  
  <p>Convert the numeric columns to numeric:</p>
  
  <pre><code>test.df[, c(2:3)] &lt;- sapply(test.df[, c(2:3)], as.numeric)
  summary(test.df)
   SIDE                 n           c1       
   Length:5           Min.   :1   Min.   :256.0  
   Class :character   1st Qu.:2   1st Qu.:258.0  
   Mode  :character   Median :3   Median :350.0  
                      Mean   :3   Mean   :324.8  
                      3rd Qu.:4   3rd Qu.:360.0  
                      Max.   :5   Max.   :400.0  
  </code></pre>
  
  <p>So the dataframe is now as I expect it - 1 column of character data and 2 of numeric. However if I change one of the rows again:</p>
  
  <pre><code>test.df[5,]&lt;-cbind("A",5,360)
  summary(test.df)
   SIDE                n                  c1           
   Length:5           Length:5           Length:5          
   Class :character   Class :character   Class :character  
   Mode  :character   Mode  :character   Mode  :character  
  </code></pre>
  
  <p>it has gone back to all character!</p>
  
  <p>Is there any way to ensure that when I append/change data in the dataframe that it keeps the appropriate classes ?</p>
  
  <p>Thanks, Pete</p>