I have a dataframe as such:
Response Spent Saved
1 Yes 100 25
2 Yes 200 50
3 No 20 2
4 No 13 3
I would like to sum up the amounts Spent and Saved, depending on the Response, ie:
Response Spent Saved
1 Yes 300 75
2 No 33 5
Right now, I am using a hackneyed approach, where I subset the dataframe into 2 new dataframes, convert the 2nd and 3rd columns into numeric data, do a colSums on each column individually, then save the outputs into a vector, then create a new dataframe....suffice to say it is a terrible approach.
How could I do this is a more effective manner?
Thanks for reading