Hi
I'm still very new to R so apologies for tedious questions.
I have the dataframe:
Code Country Date.x Continent NewCases NewDeaths
1 ARG Argentina 2020-03-14 South America 3 1
2 ARG Argentina 2020-03-14 South America 3 1
3 ARG Argentina 2020-03-14 South America 3 1
4 ARG Argentina 2020-03-14 South America 3 1
5 ARG Argentina 2020-03-14 South America 3 1
6 ARG Argentina 2020-03-14 South America 3 1
Recovered Date.y NewTests Population GDP GDPCapita
1 1 2020-03-04 0 44494502 637486 14400
2 1 2020-03-06 0 44494502 637486 14400
3 1 2020-03-07 0 44494502 637486 14400
4 1 2020-03-08 0 44494502 637486 14400
5 1 2020-03-09 0 44494502 637486 14400
6 1 2020-03-16 0 44494502 637486 14400
and I'm looking to add 4 new cumulative variables, "Cumulative_Cases", "Cumulative_Deaths", "Cumulative_Recovered" & "Cumulative_Tests", for each country up to the date of the observation.
My understanding is I need to firstly, arrange the dataframe by date and country? Then for each new variable groupby country then mutate using the cumsum function?
p.s. You had a good instinct to share something about the data of concern, you even styled it which is appreciated ! however, the way you did it does not facilitate easy copy and pasting of your data, so a user can easily add it to their R session.
Thanks @nirgrahamuk really appreciate the tips on how to provide a better example I'll definitely keep it in mind for next time!
I've tried using this code to arrange my dataframe