generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedian_iqr_age.R
34 lines (22 loc) · 1.19 KB
/
median_iqr_age.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
# Load libraries ---------------------------------------------------------------
print('Load libraries')
library(magrittr)
# Create empty output ----------------------------------------------------------
print('Create empty output')
df <- data.frame(cohort = character(),
median_iqr_age = character())
# Loop over cohorts ------------------------------------------------------------
print("Loop over cohorts")
for (cohort in c("prevax_extf","vax","unvax_extf")) {
# Load data ------------------------------------------------------------------
print(paste0("Load data for cohort: ",cohort))
tmp <- readr::read_rds(paste0("output/input_",cohort,"_stage1.rds"))
# Calculate median (IQR) age -------------------------------------------------
print("Calculate median (IQR) age")
df[nrow(df)+1,] <- c(cohort, paste0(quantile(tmp$cov_num_age)[3]," (",
quantile(tmp$cov_num_age)[2],"-",
quantile(tmp$cov_num_age)[4],")"))
}
# Save median (IQR) age --------------------------------------------------------
print('Save median (IQR) age')
write.csv(df, "output/median_iqr_age.csv", row.names = FALSE)