title: aggregating data using dplyr
body: <p>I am working with a large data set that I have pulled in from a database using RODBC. What I want to do is aggregate this data in a more manageable way. So far I have one <code>df</code> that looks something along the lines of this:</p>
  
  <pre><code>head(commercials)
  ReportPeriod Year Customer  CustomerNumber TradingGroup ItemCode ItemDesc Vol
  1 2018-01    2018 Ted's Bar 1234           Ted's PLC    1        Packing  50
  2 2018-01    2018 Ted's Res 4567           Ted's PLC    1        Packing  100
  3 2018-02    2018 Ted's Bar 1234           Ted's PLC    1        Packing  60
  4 2018-02    2018 Ted's Res 4567           Ted's PLC    1        Packing  120
  </code></pre>
  
  <p>There are other variables in the above field that relate to other item and customer information that I'm not interested in as well as variables like sales value, purchase value, and gross profit that I am.</p>
  
  <p>I want to drop all the variables that I'm not interested in and aggregate all the data by <code>TradingGroup</code> so I can see a sum of all the sales by item by TradingGroup instead of individual customer. Hence the second <code>df</code> is grouped by distinct values of the <code>TradingGroup</code> variable. I want to be able to sum all values for volume, sales value etc from the first <code>df</code> and append them to the end of the second df</p>
  
  <pre><code>head(CTG)
    TradingGroup     Channel     ItemCode ItemDes Vol
  1 Ted's PLC        Hospitality 1        Packing ?
  </code></pre>
  
  <p>I thought I'd be able to use some sort of left_join() in order to perform this operation as below:</p>
  
  <pre><code>CTGcommercials&lt;-left_join(CTG,commercials)%&gt;%group_by(TradingGroup,Channel,ItemCode,ItemDesc)%&gt;%
          summarize(sum=n())
  </code></pre>
  
  <p>This approach definitely works as I've tried this approach using a count in a similar scenario, but the column appended to the end of second df isn't quite what I'm expecting. The values in the vol column should be aggregated to one line: </p>
  
  <p>50+100+60+120=330</p>
  
  <p>Any ideas?</p>