title: Convert column classes in data.table
body: <p>I have a problem using data.table: How do I convert column classes? Here is a simple example: With data.frame I don't have a problem converting it, with data.table I just don't know how:</p>
  
  <pre><code>df &lt;- data.frame(ID=c(rep("A", 5), rep("B",5)), Quarter=c(1:5, 1:5), value=rnorm(10))
  #One way: http://stackoverflow.com/questions/2851015/r-convert-data-frame-columns-from-factors-to-characters
  df &lt;- data.frame(lapply(df, as.character), stringsAsFactors=FALSE)
  #Another way
  df[, "value"] &lt;- as.numeric(df[, "value"])
  
  library(data.table)
  dt &lt;- data.table(ID=c(rep("A", 5), rep("B",5)), Quarter=c(1:5, 1:5), value=rnorm(10))
  dt &lt;- data.table(lapply(dt, as.character), stringsAsFactors=FALSE) 
  #Error in rep("", ncol(xi)) : invalid 'times' argument
  #Produces error, does data.table not have the option stringsAsFactors?
  dt[, "ID", with=FALSE] &lt;- as.character(dt[, "ID", with=FALSE]) 
  #Produces error: Error in `[&lt;-.data.table`(`*tmp*`, , "ID", with = FALSE, value = "c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2)") : 
  #unused argument(s) (with = FALSE)
  </code></pre>
  
  <p>Do I miss something obvious here? </p>
  
  <p>Update due to Matthew's post: I used an older version before, but even after updating to 1.6.6 (the version I use now) I still get an error.</p>
  
  <p>Update 2: Let's say I want to convert every column of class "factor" to a "character" column, but don't know in advance which column is of which class. With a data.frame, I can do the following:</p>
  
  <pre><code>classes &lt;- as.character(sapply(df, class))
  colClasses &lt;- which(classes=="factor")
  df[, colClasses] &lt;- sapply(df[, colClasses], as.character)
  </code></pre>
  
  <p>Can I do something similar with data.table?</p>
  
  <p>Update 3: </p>
  
  <blockquote>
    <p>sessionInfo()
        R version 2.13.1 (2011-07-08)
        Platform: x86_64-pc-mingw32/x64 (64-bit)</p>
  </blockquote>
  
  <pre><code>locale:
  [1] C
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] data.table_1.6.6
  
  loaded via a namespace (and not attached):
  [1] tools_2.13.1
  </code></pre>