title: Column that counts number of time an element appears and average in r
body: <p>An example of the data set I have is given below.</p>
  
  <pre><code>Month_Ori_Dest   Cat    Num  
  1-LA/LON          A      2
  1-LA/LON          A      3
  2-LON/LA          B      2
  3-LON/LA          A      5
  3-LON/LA          B      2
  </code></pre>
  
  <p>1) Firstly I want to group by Month_Ori_Dest and Cat and insert a column that calculates the number of times that combination appears. E.g.</p>
  
  <pre><code>Month_Ori_Dest   Cat    Num  Count
  1-LA/LON          A      2     2
  1-LA/LON          A      3     2
  2-LON/LA          B      2     1
  3-LON/LA          A      5     1
  3-LON/LA          B      2     1
  </code></pre>
  
  <p>2) I then want to insert a column based on the same groupings (Month_Ori_Dest and Cat) to calculate the average Num for each group. E.G.</p>
  
  <pre><code>Month_Ori_Dest   Cat    Num  Count  AverageNum
  1-LA/LON          A      2     2        2.5
  1-LA/LON          A      3     2        2.5
  2-LON/LA          B      2     1         2
  3-LON/LA          A      5     1         5
  3-LON/LA          B      2     1         2
  </code></pre>
  
  <p>Any help would be great.
  Thanks!</p>