I have the following dataset:
Year Company Product Sales
2017  X       A       10
2017  Y       A       20
2017  Z       B       20 
2017  X       B       10
2018  X       B       20
2018  Y       B       30
2018  X       A       10 
2018  Z       A       10
I want to obtain the following summary:
Year Product Sales
2017 A       30
     B       30
2018 A       50 
     B       20
and also the following summary:
Year Company Sales
2017  X      20
      Y      20 
      Z      20
2018  X      50
      Y      10 
      Z      10
Is there any way to do it without using loops?
I know I could do something with the function aggregate, but I don't know how to proceed with it without mixing the data of company, product and year. For example, I get the total sales of product A and B, but it's mixing the sales of both years instead of giving A and B in 2017, and separated in 2018.
Do you have any suggestions?
 
     
    