title: why is data.table so slow in this example in R
body: <p>This is related to <a href="https://stackoverflow.com/questions/26085374/r-view-all-the-columns-names-with-any-na">R- view all the columns names with any NA</a></p>
  
  <p>I compared data.frame and data.table versions and found that data.table is 10x slower. This is contrary to most code with data.table which are really much faster than data.frame versions. </p>
  
  <pre><code>set.seed(49)
  df1 &lt;- as.data.frame(matrix(sample(c(NA,1:200), 1e4*5000, replace=TRUE), ncol=5000))
  
  library(microbenchmark) 
  f1 &lt;- function() {names(df1)[sapply(df1, function(x) any(is.na(x)))]}
  f2 &lt;- function() { setDT(df1); names(df1)[df1[,sapply(.SD, function(x) any(is.na(x))),]]  } 
  microbenchmark(f1(), f2(), unit="relative")
  Unit: relative
   expr      min       lq   median       uq      max neval
   f1()  1.00000  1.00000 1.000000 1.000000 1.000000   100
   f2() 10.56342 10.20919 9.996129 9.967001 7.199539   100
  </code></pre>
  
  <p>setDT beforehand: </p>
  
  <pre><code>set.seed(49)
  df1 &lt;- as.data.frame(matrix(sample(c(NA,1:200), 1e4*5000, replace=TRUE), ncol=5000))
  setDT(df1)
  
  library(microbenchmark) 
  f1 &lt;- function() {names(df1)[sapply(df1, function(x) any(is.na(x)))]}
  f2 &lt;- function() {names(df1)[df1[,sapply(.SD, function(x) any(is.na(x))),]]  } 
  microbenchmark(f1(), f2(), unit="relative")
  Unit: relative
   expr      min       lq   median       uq      max neval
   f1()  1.00000  1.00000  1.00000  1.00000 1.000000   100
   f2() 10.64642 10.77769 10.79191 10.77536 7.716308   100
  </code></pre>
  
  <p>What could be the reason?</p>