-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtotal_vacinas_doses.R
38 lines (31 loc) · 1.06 KB
/
total_vacinas_doses.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
suppressPackageStartupMessages({
if(!require(data.table)){install.packages("data.table"); library(data.table)}
if(!require(tidyverse)){install.packages("tidyverse"); library(tidyverse)}
})
###
ini = Sys.time()
files <- list.files("output/wide")[!grepl("[1-9].csv", list.files("output/wide"))]
da <- data.frame()
for(i in files) {
state = substr(i,22,23) #
print(state)
df <- read.csv(paste0("output/wide/",i))
df[df==""] <- NA
df$dose <- ""
df$dose[!is.na(df$data_D1) & is.na(df$data_D2) & is.na(df$data_R)] <- "D1"
df$dose[!is.na(df$data_D2) & is.na(df$data_R)] <- "D2"
df$dose[is.na(df$data_DU) & !is.na(df$data_R)] <- "R" #
df$dose[!is.na(df$data_DU)] <- "DU"
df2 = df %>%
mutate(agegroup = factor(agegroup)) %>%
count(vacina_D1, dose, agegroup, .drop = FALSE) %>%
drop_na(vacina_D1, dose, agegroup) %>%
arrange(vacina_D1, dose, agegroup) %>%
filter(dose != "DU") %>%
mutate(UF = state)
da <- rbind(da, df2)
}
da <- da %>% filter(vacina_D1 != "Janssen")
fwrite(da, file = "output/total_vacinas.csv")
fin = Sys.time()
fin - ini