I have a dataframe called sales.
I would like to sum each month of sales by the common identifier, ID.
What I am finding hard, is how to do this conditional on there being a return value.
For example, when I sum sales_Feb1980 for ID 2, only the observations with returns should be included and the ones without should be ignored?
What the data looks like.. I have many more rows and columns.
id name Returns_jan1980 Returns_feb1980 Sales_Jan1980 Sales_Feb1980
2b LA 4.7% 5.6% 100 100
2b LA 5.7% 250 100
2b LA 6.3% 5.8% 50 100
5a NY 5.6% 30 200
5a NY 5.7% 3.6% 50 100
Correct output
id name Sales_Jan1980 Sales_Jan19080
2 LA 400 200
5 NY 50 300
Any help is appreciated.