totdal_deaths_confirmed_cases_60_days_only = swine_flu_cases %>%
filter(Confirmed >0) %>%
group_by(Country) %>%
summarise(top_n((total_confirmed_cases = sum(Confirmed), total_deaths = sum(Deaths),60))
So I have a dataframe called swine_flu_cases, and have variables such as:
Country Date Confirmed Recovered Death
What I am trying to do is I want to sum up the groups confirmed and deaths variables in the data frame but only for the first 60 rows/entries per country. I tried using the top_n function but I am not too sure how to apply it into my dataframe before I do the summary. I also tried using slice_max function but my pc doesn't seem to have the function installed even though I loaded the dplyr
package so I can't quite figure that out either.
Any suggestions on how I could accomplish this would be appreciated