Skip to content
Snippets Groups Projects
Commit a015fbde authored by Ben Anderson's avatar Ben Anderson
Browse files

updated function to create uniq pid & diarypid using a hash function to ensure...

updated function to create uniq pid & diarypid using a hash function to ensure unique ids across all years (including UK TU 2014)
parent e94fae2f
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,8 @@ lb_myRequiredPackages <- function(x,y){ ...@@ -17,7 +17,8 @@ lb_myRequiredPackages <- function(x,y){
} }
# Use the function to load the libraries required by this code # Use the function to load the libraries required by this code
reqLibs <- c("data.table" # fast data munching reqLibs <- c("data.table", # fast data munching
"openssl" # for hashing ids
) )
print(paste0("Loading the following libraries using lb_myRequiredPackages: ", reqLibs)) print(paste0("Loading the following libraries using lb_myRequiredPackages: ", reqLibs))
...@@ -30,6 +31,33 @@ ba_tidyNum <- function(number) { ...@@ -30,6 +31,33 @@ ba_tidyNum <- function(number) {
format(number, big.mark=",", scientific=FALSE) format(number, big.mark=",", scientific=FALSE)
} }
###
ba_MTUScreateIds <- function(dt){
# create a unique pid & unique diary pid that will be unique across all years
dt <- dt[, ba_pidChar := paste0(survey, swave, msamp, hldid,persid,sep= "_")] # force character
dt <- dt[, ba_pid := md5(ba_pidChar)] # hash
dt <- dt[, ba_diarypid := paste0(ba_pid, id, sep= "_")] # force character
}
# # diarypid
# mtusUKEpsDT$ba_diarypid <-
# group_indices(mtusUKEpsDT, survey,
# swave,
# msamp,
# hldid,
# persid,
# id
# )
#
# # pid
# mtusUKEpsDT$ba_pid <-
# group_indices(mtusUKEpsDT, survey,
# swave,
# msamp,
# hldid,
# persid
# )
### ###
ba_MTUScreateEpisodeStartEndDateTimes <- function(dt){ ba_MTUScreateEpisodeStartEndDateTimes <- function(dt){
# Setting up corrected start and end timestamps # Setting up corrected start and end timestamps
...@@ -53,8 +81,8 @@ ba_MTUScreateAllEpisodeStartTimesAsString <- function(dt){ ...@@ -53,8 +81,8 @@ ba_MTUScreateAllEpisodeStartTimesAsString <- function(dt){
# start time as string # start time as string
# Use the fake start time we created earlier which includes all cases # Use the fake start time we created earlier which includes all cases
dt <- dt[, st_hour := as.POSIXlt(dt$r_epStartDateTime)$hour] dt <- dt[, st_hour := as.POSIXlt(dt$r_epStartDateTime)$hour]
dt <- dt[, st_mins := as.POSIXlt(mtusUKEpsDT$r_epStartDateTime)$min] dt <- dt[, st_mins := as.POSIXlt(dt$r_epStartDateTime)$min]
dt <- dt[, str_epStartTime := paste0(dt$st_hour, dt <- dt[, r_epStartTimeStr := paste0(dt$st_hour,
":", ":",
dt$st_mins dt$st_mins
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment