knitr::opts_chunk$set(echo = TRUE)

library(dplyr)
library(readxl)

cdate <- Sys.Date()

myxlsx0 <- paste0("C:/Users/langhe/Documents/Tanzania/timci_exports/export_", cdate, "/02_Tanzania_main_study_interim_analysis_lock/08b_Tanzania_cleaned_datasets/02_timci_day0_data.xlsx")
myxlsx1 <- paste0("C:/Users/langhe/Documents/Tanzania/timci_exports/export_", cdate, "/02_Tanzania_main_study_interim_analysis_lock/08b_Tanzania_cleaned_datasets/04a_timci_followup_day7_data.xlsx")
myxlsx2 <- paste0("C:/Users/langhe/Documents/Tanzania/timci_exports/export_", cdate, "/02_Tanzania_main_study_interim_analysis_lock/08b_Tanzania_cleaned_datasets/06a_timci_followup_day28_data.xlsx")

set.seed(2021)

Loading data

df0 <- readxl::read_excel(myxlsx0, col_types = "text")
print(nrow(df0))
df1 <- readxl::read_excel(myxlsx1, col_types = "text")
print(nrow(df1))
df2 <- readxl::read_excel(myxlsx2, col_types = "text")
print(nrow(df2))

Random selection

random_selection0 <- df0 %>%
  group_by(consult_reason) %>%
  sample_n(3)
print(random_selection0)
random_selection1 <- df1 %>%
  group_by(fu_type) %>%
  sample_n(3)
print(random_selection1)
random_selection2 <- df2 %>%
  group_by(fu_type) %>%
  sample_n(3)
print(random_selection2)
openxlsx::write.xlsx(random_selection0,
                     "stat_example_day0.xlsx",
                     rowNames = FALSE,
                     overwrite = TRUE)
openxlsx::write.xlsx(random_selection1,
                     "stat_example_day7.xlsx",
                     rowNames = FALSE,
                     overwrite = TRUE)
openxlsx::write.xlsx(random_selection2,
                     "stat_example_day28.xlsx",
                     rowNames = FALSE,
                     overwrite = TRUE)


Thaliehln/timci documentation built on April 8, 2024, 3:38 p.m.