I have the following tibble of data showing net profit for stocktrades on given days:
# A tibble: 114 x 3
date profit_loss net_profit
<date> <dbl> <dbl>
1 2020-01-08 1 2105
2 2020-01-15 1 2415
3 2020-01-20 1 305
4 2020-01-21 1 1120
5 2020-01-23 1 235
6 2020-01-23 1 235
7 2020-01-30 1 -290
8 2020-01-30 1 -2035
9 2020-02-03 1 7640
10 2020-02-06 1 -2035
# ... with 104 more rows
As you can see there are several instances where there are more than one trade per day. I would like to combine the rows that have the same date and sum the profit for those dates together to create a new dataframe that has all unique dates.
Is there a way to do this with group_by and summarise? Or do I need to write some logical code that loops through the dataframe and compares the dates?
Any help would be greatly appreciated.