@@ -13,13 +13,19 @@ kinds of tasks with `epi_df` objects. We'll work with county-level reported
13
13
COVID-19 cases in MA and VT.
14
14
15
15
``` {r, message = FALSE, eval= FALSE, warning= FALSE}
16
+ library(readr)
16
17
library(epidatr)
17
- library(covidcast)
18
18
library(epiprocess)
19
19
library(dplyr)
20
20
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
+ ) %>%
23
29
filter(STNAME %in% c("Massachusetts", "Vermont"), STNAME != CTYNAME) %>%
24
30
select(geo_value = FIPS, county_name = CTYNAME, state_name = STNAME)
25
31
@@ -33,15 +39,15 @@ x <- pub_covidcast(
33
39
time_values = epirange(20200601, 20211231),
34
40
) %>%
35
41
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") ) %>%
37
43
as_epi_df(as_of = as.Date("2024-03-20"))
38
44
```
39
45
40
46
The data contains 16,212 rows and 5 columns.
41
47
42
48
``` {r, echo=FALSE, warning=FALSE, message=FALSE}
49
+ library(readr)
43
50
library(epidatr)
44
- library(covidcast)
45
51
library(epiprocess)
46
52
library(dplyr)
47
53
@@ -110,15 +116,16 @@ help avoid bugs in further downstream data processing tasks.
110
116
Let's first remove certain dates from our data set to create gaps:
111
117
112
118
``` {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
+
113
125
# First make geo value more readable for tables, plots, etc.
114
126
x <- 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 = ", ")) %>%
122
129
select(geo_value, time_value, cases)
123
130
124
131
xt <- as_tsibble(x) %>% filter(cases >= 3)
0 commit comments