title: R table function: how to sum instead of counting?
body: <p>Suppose I have data in an R table which looks like this:</p>
  
  <pre><code>Id  Name Price sales Profit Month Category Mode
  1   A     2     5     8       1     X       K
  1   A     2     6     9       2     X       K
  1   A     2     5     8       3     X       K
  1   B     2     4     6       1     Y       L
  1   B     2     3     4       2     Y       L
  1   B     2     5     7       3     Y       L
  2   C     2     5    11       1     X       M
  2   C     2     5    11       2     X       L
  2   C     2     5    11       3     X       K
  2   D     2     8    10       1     Y       M
  2   D     2     8    10       2     Y       K
  2   D     2     5    7        3     Y       K
  3   E     2     5    9        1     Y       M
  3   E     2     5    9        2     Y       L
  3   E     2     5    9        3     Y       M
  3   F     2     4    7        1     Z       M
  3   F     2     5    8        2     Z       L
  3   F     2     5    8        3     Z       M
  </code></pre>
  
  <p>If I use the <code>table</code> function on this data like:</p>
  
  <pre><code>table(df$Category, df$Mode)
  </code></pre>
  
  <p>It will show me under each mode which category has how many observations. It's like counting the number of items in each category under each mode. </p>
  
  <p>But what if I want the table to show under each <code>Category</code> which <code>Mode</code> earned how much <code>Profit</code> (sum or mean) and not the total count?</p>
  
  <p>Is there any way to do this with the <code>table</code> function or another function in R?</p>