title: Calculate sum of a list of variables by group
body: <p>I have a data.table with one key and about 100 numeric rows, one of which is set to key. I would like to create a new variable that contains summation of each numeric rows, grouped by key.</p>
  
  <p>For example, my data right now is</p>
  
  <pre><code>ID Count1 Count2 Count3
  1   1      3      0
  1   3      3      3
  2   1      2      1
  3   1      1      2
  </code></pre>
  
  <p>What I would like to have is:</p>
  
  <pre><code>ID Count1 Count2 Count3
  1   4      6      3
  2   1      2      1
  3   1      1      2
  </code></pre>
  
  <p>I have tried so many ways to get this. I know I can do:</p>
  
  <pre><code>Y &lt;- X[, list(Count=sum(Count1), Count2=sum(Count2), Count3=sum(Count3), by = ID]
  </code></pre>
  
  <p>However, I have hundreds of variables, and I only get their names on a list. How should I go about handling this?</p>
  
  <p>Thanks a lot for your help.</p>
  
  <p>Here is a code to generate test data:</p>
  
  <pre><code>ID &lt;-c(rep(210, 9), rep(3917,6))
  Count1 &lt;- c(1,1,0,1,3,1,4,1,1,1,1,1,1,0,1)
  Count2 &lt;- c(1,0,0,1,0,1,0,1,1,1,1,1,1,0,1)
  Count3 &lt;- c(1,0,0,1,0,1,0,1,1,1,1,1,1,0,1)
  x &lt;- data.table(ID, Count1, Count2, Count3)
  setkey(x, ID)
  </code></pre>