forked from covid19datahub/COVID19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld.R
46 lines (29 loc) · 811 Bytes
/
world.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
world <- function(level, cache){
# fallback
if(level>2)
return(NULL)
# download
x <- jhucsse_git(file = "global", cache = cache, level = level)
# iso
x$iso_alpha_3 <- id(x$country, iso = "ISO", ds = "jhucsse_git", level = 1)
# level
if(level==1){
# id
x$id <- x$iso_alpha_3
# tests
o <- ourworldindata_org(cache = cache)
x <- merge(x, o, by = c('date','iso_alpha_3'), all.x = TRUE)
}
if(level==2){
# id
x <- x %>%
dplyr::group_by_at('iso_alpha_3') %>%
dplyr::group_map(.keep = TRUE, function(x, iso){
x$id <- id(x$state, iso = iso[[1]], ds = "jhucsse_git", level = level)
return(x)
}) %>%
dplyr::bind_rows()
}
# return
return(x)
}