@@ -13,13 +13,19 @@ kinds of tasks with `epi_df` objects. We'll work with county-level reported
1313COVID-19 cases in MA and VT.
1414
1515``` {r, message = FALSE, eval= FALSE, warning= FALSE}
16+ library(readr)
1617library(epidatr)
17- library(covidcast)
1818library(epiprocess)
1919library(dplyr)
2020
21- # Use covidcast::county_census to get the county and state names
22- y <- covidcast::county_census %>%
21+ # Get mapping between FIPS codes and county&state names:
22+ y <- read_csv("https://github.com/cmu-delphi/covidcast/raw/c89e4d295550ba1540d64d2cc991badf63ad04e5/Python-packages/covidcast-py/covidcast/geo_mappings/county_census.csv", # nolint: line_length_linter
23+ col_types = c(
24+ FIPS = col_character(),
25+ CTYNAME = col_character(),
26+ STNAME = col_character()
27+ )
28+ ) %>%
2329 filter(STNAME %in% c("Massachusetts", "Vermont"), STNAME != CTYNAME) %>%
2430 select(geo_value = FIPS, county_name = CTYNAME, state_name = STNAME)
2531
@@ -33,15 +39,15 @@ x <- pub_covidcast(
3339 time_values = epirange(20200601, 20211231),
3440) %>%
3541 select(geo_value, time_value, cases = value) %>%
36- full_join (y, by = "geo_value") %>%
42+ inner_join (y, by = "geo_value", relationship = "many-to-one", unmatched = c("error", "drop") ) %>%
3743 as_epi_df(as_of = as.Date("2024-03-20"))
3844```
3945
4046The data contains 16,212 rows and 5 columns.
4147
4248``` {r, echo=FALSE, warning=FALSE, message=FALSE}
49+ library(readr)
4350library(epidatr)
44- library(covidcast)
4551library(epiprocess)
4652library(dplyr)
4753
@@ -110,15 +116,16 @@ help avoid bugs in further downstream data processing tasks.
110116Let's first remove certain dates from our data set to create gaps:
111117
112118``` {r}
119+ state_naming <- read_csv("https://github.com/cmu-delphi/covidcast/raw/c89e4d295550ba1540d64d2cc991badf63ad04e5/Python-packages/covidcast-py/covidcast/geo_mappings/state_census.csv", # nolint: line_length_linter
120+ col_types = c(NAME = col_character(), ABBR = col_character())
121+ ) %>%
122+ transmute(state_name = NAME, abbr = tolower(ABBR)) %>%
123+ as_tibble()
124+
113125# First make geo value more readable for tables, plots, etc.
114126x <- x %>%
115- mutate(
116- geo_value = paste(
117- substr(county_name, 1, nchar(county_name) - 7),
118- name_to_abbr(state_name),
119- sep = ", "
120- )
121- ) %>%
127+ inner_join(state_naming, by = "state_name", relationship = "many-to-one", unmatched = c("error", "drop")) %>%
128+ mutate(geo_value = paste(substr(county_name, 1, nchar(county_name) - 7), state_name, sep = ", ")) %>%
122129 select(geo_value, time_value, cases)
123130
124131xt <- as_tsibble(x) %>% filter(cases >= 3)
0 commit comments