Question: 5. Check that States and County data frames include daily cases and deaths. If the data on cases and deaths is cumulative data, then create
5. Check that States and County data frames include daily cases and deaths. If the data on cases and deaths is cumulative data, then create columns for day-cases and day-deaths. Dplyr library offers necessary methods to achieve this: states = states %>% arrange(date) %>% mutate(new_cases = cases-lag(cases)) %>% mutate(new_deaths = deaths-lag(deaths)) Check if na or NaN1 values are not generated in the data-frames. Deal with them before going to the next step.
6. Sometimes, the oscillating nature of daily cases makes it difficult to interpret any trends. For this reason, moving averages are considered more stable indicators. Create 7 day moving averages of cases and deaths for the States and Counties data. The dplyr and zoo packages will help in creating these derived fields. states = states %>% group_by(state) %>% arrange(state, date) %>% mutate(case_avg7 = rollmean(x = new_cases, 7, align = "right", fill = NA)) %>% mutate(death.avg7 = rollmean(x = new_deaths, 7, align = "right", fill = NA))
7. Finally, create a new field to show mortality ratio in States and County data frames. Use the newly created moving averages in creating MR values2 .
8. Finally, check the State and County data frames for NA and NaN values and clean them up if necessary.
help with code using rstudio! thanks!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
