title: How can you calculate column sums based on a condition using data.table?
body: <p>I have a table of IDs and 1000 columns of random values. I want to group the IDs and calculate the number of values less than 0.01 for each column. </p>
  
  <p>I used a loop to merge a table iteratively but have to access the column name using <code>eval</code> and <code>parse</code>. Unfortunately it's taking too long to run. I've implemented a similar for loop for a different problem in the past so I know iterative merging doesn't take that long. I think the <code>eval</code> and <code>parse</code> is what's slowing the code down. Is there a way to do this without using those functions?</p>
  
  <pre><code>library(data.table)
  set.seed(1)
  data &lt;- data.table(ID = rep(LETTERS[1:3], 13), 
    col1 = rnorm(39), 
    col2 = rnorm(39), 
    col3 = rnorm(39))
  </code></pre>
  
  <p>I need to produce the following for each column: <code>data[,sum(col1 &lt; 0.01)]; data[,sum(col2 &lt; 0.01)]; data[,sum(col3 &lt; 0.01)]</code></p>
  
  <pre><code>columns &lt;- colnames(data)[2:ncol(data)]
  d &lt;- data[,.N, keyby = ID][,N := NULL]
  for (col in 1:length(columns)) {
      sum_table &lt;-  data[, sum(eval(parse(text = ..columns[col])) &lt; 0.01), by = ID]
  d &lt;- d[sum_table]
  }
  </code></pre>
  
  <p>I would like to be able to reproduce this without using <code>eval</code> and <code>parse</code> so the run time is faster.</p>