title: How to convert character to numeric within data.table for specific columns?
body: <p>Dataset below has the characteristics of my large dataset.  I am managing it in data.table, some columns are loaded as chr despite they are numbers and I want to convert them into numerics and these column names are known  </p>
  
  <pre><code>dt = data.table(A=LETTERS[1:10],B=letters[1:10],C=as.character(runif(10)),D = as.character(runif(10))) # simplified version
  strTmp = c('C','D') # Name of columns to be converted to numeric
  
  # columns converted to numeric and returned a  10 x 2 data.table
  dt.out1 &lt;- dt[,lapply(.SD, as.numeric, na.rm = T), .SDcols = strTmp]
  </code></pre>
  
  <p>I am able to convert those 2 columns to numeric with the code above however I want to update dt instead.  I tried using := however it didn't work.  I need help here!</p>
  
  <pre><code>dt.out2 &lt;- dt[, strTmp:=lapply(.SD, as.numeric, na.rm = T), .SDcols = strTmp] # returned a 10 x 6 data.table (2 columns extra)
  </code></pre>
  
  <p>I even tried the code below (coded like a data.frame - not my ideal solution even if it works as I am worried in some cases the order might change) but it still doesn't work.  Can someone let me know why it doesn't work please?</p>
  
  <pre><code>dt[,strTmp,with=F] &lt;- dt[,lapply(.SD, as.numeric, na.rm = T), .SDcols = strTmp]
  </code></pre>
  
  <p>Thanks in advance!  </p>