library(readxl) library(writexl) path <- "" #define path where population.xlsx is located df <- read_xlsx(paste0(path, "population.xlsx")) df$used=0 #sample size for each screening wave k <- 100 base_seed <- #To preserve anonymity of the studies included in our final sample, this number has been removed ###################################################################################### ### To draw a new wave: ### ### 1. Copy & paste this entire section at the end of the script ### ### 2. Fill in the wave order number and the date (DD-MM-YYYY) ### ### 3. Save the script file ### ### 4. Run the entire script from top to bottom ### ### ### ### ### cur_date <- "01.01.1970" wave <- 1 set.seed(paste0(base_seed,wave)) ### ### ### sample k IDs from id column of df, but only when used == 0 ### df_sample<-df[sample((1:nrow(df))[df$used == 0], k), 1] df_sample <- as.integer(as.matrix(df_sample)) cat(sort(df_sample), sep='\n') ### ### ### mark entries as used in id column of df ### for(i in 1:k) { df[which(df$id == df_sample[i]), 5]=wave } ### ### write_xlsx(subset(df,used==wave),paste0(path,"wave",wave,"_",cur_date,".xlsx")) ### ### ######################################################################################