-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcollate.R
30 lines (23 loc) · 826 Bytes
/
collate.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Collate the latest data per data point, because Google's reports are a
# sliding window, so some dates are reported every week for a few weeks.
library(tidyverse)
library(fs)
library(vroom)
all_country_data <-
dir_ls(glob = "*-country.tsv") %>%
map_dfr(vroom, delim = "\t", col_types = "cdccDcddccdddD")
latest_country_data <-
all_country_data %>%
group_by(country_code, region_name, category, date) %>%
top_n(1, report_date) %>%
ungroup()
write_tsv(latest_country_data, "country.tsv")
all_region_data <-
dir_ls(glob = "*-region.tsv") %>%
map_dfr(vroom, delim = "\t", col_types = "cdccDcddccdddD")
latest_region_data <-
all_region_data %>%
group_by(country_code, region_name, sub_region_name, category, date) %>%
top_n(1, report_date) %>%
ungroup()
write_tsv(latest_region_data, "region.tsv")