title: Sum multiple columns
body: <p>I am trying to write a function that will sum the column(s) in the data frame according to the values in the first two columns.For example I have a matrix M,</p>
  
  <pre><code>Crs gr  P_7 P_8      
  38  1   3   16
  38  1   12  45
  38  1   9   28
  40  2   3   9
  40  2   14  29
  40  1   4   3
  40  2   8   2
  </code></pre>
  
  <p>I want to sum the columns according to column1(crs) first and then column2(gr). Result will be,</p>
  
  <pre><code>    Crs gr  P_7  P_8      
      38  1   24  89
      40  2   25  40
      40  1   4   3
  </code></pre>
  
  <p>Currently I am using,</p>
  
  <pre><code>M &lt;- M[, list(sum(P_7),sum(P_8)), by=list(Crs,gr)]
  </code></pre>
  
  <p>But the problem with this, is that I have to define the names of columns which wont be fixed. So, I was wondering how can I do this without defining the names of the columns.
  Thanks in advance! </p>