Currently in the Metabase analysis code, we create subsets of data to then run tables.
We want to use the select
function instead.
data_baseline_survey <- with(plhdata_org_clean, data.frame(app_user_id,
Org,
rp.contact.field.survey_welcome_completed, rp.contact.field.user_gender,
rp.contact.field.user_age, rp.contact.field.household_adults,
rp.contact.field.household_teens, rp.contact.field.household_babies,
rp.contact.field.household_children))
colnames(data_baseline_survey) <- naming_conventions(colnames(data_baseline_survey), replace = "rp.contact.field.")
two_way_table_baseline <- NULL
# to run all the "Habits" tables individually:
for (i in 3:length(data_baseline_survey)){
two_way_table_baseline[[(i-2)]] <- two_way_table(data = data_baseline_survey,
row_var = names(data_baseline_survey)[i])
# to get user IDs
# user_id_print(names(data_baseline_survey)[i])
}
names(two_way_table_baseline) <- names(data_baseline_survey)[3:length(data_baseline_survey)]
# then to access a table:
two_way_table_baseline$`Household babies`
baseline_survey_columns <- c("rp.contact.field.survey_welcome_completed", "rp.contact.field.user_gender",
"rp.contact.field.user_age", "rp.contact.field.household_adults",
"rp.contact.field.household_teens", "rp.contact.field.household_babies",
"rp.contact.field.household_children")
two_way_table_baseline <- NULL
for (i in 1:length(baseline_survey_columns)){
two_way_table_baseline[[i]] <- two_way_table(data = plhdata_org_clean,
row_var = baseline_survey_columns[i],
replace = "rp.contact.field.")
}
names(two_way_table_baseline) <- baseline_survey_columns
two_way_table_baseline <- plhdata_org_clean %>%
dplyr::select(Org, baseline_survey_columns) %>%
purrr::map_at(baseline_survey_columns,
two_way_table(row_var = names(.), replace = "rp.contact.field."))