id   product            id2     year   cost 
 1  biscuits    202-55-3041     2017      2 
 2  biscuits    903-36-9457     2014      2 
 3  biscuits    938-33-7254     2014      2 
 4  biscuits    739-29-5963     2017      2 
 5  biscuits    731-49-5483     2017      2 
 6  biscuits    892-15-2567     2018      2 
 7  biscuits    518-79-7674     2017      2 
 8  biscuits    305-63-7908     2017      2 
This is my current data set the name of this data is called 'total1'
I am a beginner in R and I was wondering if there was a way to add up the cost of the product based on the year, for example;
In 2017 there were 10 biscuits sold
In 2018 there were 8 biscuits sold
I am trying to determine which is the least profitable year in terms of biscuits sold.
I apologise if this is answered elsewhere if it is direct me thank you.
 
     
    