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:

  1. "Confirmed": The number of confirmed cases, taken from the inputdf.
  2. "Timestamp": The timestamp taken from the inputdf.
  3. "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.

Complete the function,get_us_states(df), below, whereits input,df, is a data frame structured like

\f

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!