title: Aggregating two columns in R dataframe
body: <p>I have a dataframe in R called food:</p>
  
  <pre><code>foodID   calories   fat    protein
  
   123       0.5      0.4     0.9
   432       0.65     0.3     0.7
   123       0.32     0.6     0.5
   983       0.82     0.2     0.6
  </code></pre>
  
  <p>and I'm trying to <strong>average</strong> up the <strong>calories and protein column</strong> by <strong>foodID</strong>.</p>
  
  <p>I tried:</p>
  
  <pre><code>cal_pro &lt;- aggregate(food[2,4], list(food$foodID), function(df) mean(df))
  </code></pre>
  
  <p>But it appears that i can't select the columns to be applied the mean function by food[2,4]? Could anyone help me out on this.</p>