Question
Complete the function,get_us_states(df), below, where its input,df, is a data frame structured like the combined COVID-19 data frame (df_covid19), having the columnsProvince/State,Country/Region,Confirmed,Timestamp; and it returns
Complete the function,get_us_states(df), below, where
- its input,df, is a data frame structured like the combined COVID-19 data frame (df_covid19), having the columns"Province/State","Country/Region","Confirmed","Timestamp";
- and it returns a tibble containing only those rows ofdfthat are from the United States where the"Province/State"field is exactly the name of any one of the US states.
Regarding the second requirement, the returned object should include a row where the"Province/State"field is"Georgia", but it shouldnotinclude a row where this field is, say,"Atlanta, GA". (Put differently, we will assume the state-level accounts already include city-level counts.)
The tibble returned by your function should only have these three columns:
- "Confirmed": The number of confirmed cases, taken from the inputdf.
- "Timestamp": The timestamp taken from the inputdf.
- "ST": The two-letterabbreviationfor the state's name.
Pay attention to item (3): your returned tibble should not have the state's full name, but rather, its two-letter postal code abbreviation (e.g.,"GA"instead of"Georgia"). To help you out, here is a code cell that defines a data frame calledSTATE_NAMESthat holds both a list of state names and their two-letter abbreviations.
Note: The test cell for this exercise reuses functions defined in the test cell for Exercise 0. So even if you skipped Exercise 0, please run its test cell before running the one below.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started