-
Notifications
You must be signed in to change notification settings - Fork 1
/
add_pop_to_dengue_PR.R
48 lines (39 loc) · 1.66 KB
/
add_pop_to_dengue_PR.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
47
48
#SV Scarpino
#Nov 2018
#Add population sizes to dengue data set
#set working dir
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))#sets working directory to source file location
#libraries (not included in limits_acc_functions.R)
#########
#Globals#
#########
write_new <- FALSE #set to TRUE to save a new csv
time_stamp <- as.numeric(Sys.time())
###########
#acc funcs#
###########
###########
#Data Sets#
###########
#1. Load PR dengue data
data_out <- read.csv("Data/san_juan_dengue_data.csv")
data_out$Year <- substr(data_out$week_start_date, 1, 4)
#2. Population sizes
#from https://en.wikipedia.org/wiki/Demographics_of_Puerto_Rico
# B.R. Mitchell. International historical statistics: the Americas, 1750–2000
# "United Nations Statistics Division – Demographic and Social Statistics". Unstats.un.org. Retrieved 14 October 2017.
# "Archived copy". Archived from the original on 2017-09-27. Retrieved 2017-09-09.
#"Archived copy" (PDF). Archived from the original (PDF) on 2017-10-16. Retrieved 2017-10-03.
pop_size_pr <- read.table("PR_pop_size.txt", sep = "\t", header = TRUE, stringsAsFactors = FALSE)
years <- unique(data_out$Year)
use_pops <- which(pop_size_pr$Year %in% years)
pops <- pop_size_pr$Averagepopulation.x1000.[use_pops]*1000
tab_years <- table(data_out$Year)
data_out$population_est <- rep(pops, tab_years)
#3. Save
if(write_new == TRUE){
years_var <- as.numeric(unique(data_out$Year))
years_var <- years_var[order(years_var, decreasing = FALSE)]
filename <- paste0("Data/san_juan_dengue_data_pop_", time_stamp,"-years-", paste0(years_var, collapse = "-"), ".csv")
write.csv(x = data_out, file = filename, row.names = FALSE, quote = FALSE)
}