@nirgrahamuk here is a repex (sorry its so large) of the code I used to make the prop.test followed by some data, and replication of that data. The names list is used to conditionally select indexes to input into the prop.test, I have however removed the additional conditions and extra code, which is basically the same. Thank you in advance, for taking the time to read through this, I know its quite a pain to help people as the complexity ramps up.
As I mentioned before, sometime the mutate appends .x or .y to the end of the columns, but not all the time. I'm not sure why this occurs.
try(cor_logs <- purrr::pmap(list(df_list, item_names), function(first, forth) {
if ( forth[[2]] == forth[[3]]) {
purrr::pmap(first, ~ {
prop.test(x = c(..2, ..5), n = c(..6, ..6), correct = "FALSE")
}) %>%
purrr::map_df(broom::tidy, .id = "formula") %>%
mutate(formula = as.integer(formula)) %>%
dplyr::select(-one_of(c("parameter", "conf.low", "conf.high", "method", "alternative"))) %>%
dplyr::rename(
prop_NL_NP2 = estimate1, prop_NH_PR2 = estimate2,
high_chi = statistic, HN_pval = p.value
) %>%
dplyr::left_join(first, by = c("formula" = "row_number")) %>%
dplyr::rename(row_number = formula) %>%
dplyr::select(!1:5, 1:5)
} else {
print("ERROR in dataframe structure")
}
}))
df1<- structure(list(day = structure(c(1546300800, 1546387200, 1546473600,
1546560000, 1546646400, 1546732800, 1546819200, 1546905600, 1546992000,
1547078400), tzone = "", class = c("POSIXct", "POSIXt")), ITEM10128_0 = c(1190L,
1532L, 1110L, 1134L, 1566L, 987L, 1324L, 937L, 1007L, 1100L),
ITEM10128_1 = c(2372L, 2865L, 2751L, 3238L, 3156L, 2541L,
2224L, 2032L, 5458L, 2386L), ITEM24373_0 = c(867L, 1062L,
1151L, 1267L, 1311L, 1011L, 916L, 1095L, 1008L, 925L), ITEM24373_1 = c(1814L,
3099L, 1976L, 3610L, 3040L, 2520L, 2520L, 3411L, 2434L, 2413L
), tot_sales_pr1 = c(3004L, 4631L, 3086L, 4744L, 4606L, 3507L,
3844L, 4348L, 3441L, 3513L)), row.names = c(NA, -10L), class = c("tbl_df",
"tbl", "data.frame"))
item_names <- list(c("day", "ITEM10128", "ITEM10128", "ITEM24373", "ITEM24373"
), c("day", "ITEM10128", "ITEM10128", "ITEM24373", "ITEM24373"
), c("day", "ITEM10128", "ITEM10128", "ITEM24373", "ITEM24373"
), c("day", "ITEM10128", "ITEM10128", "ITEM24373", "ITEM24373"
))
df4 <- df1
df3 <- df1
df2 <- df1
df_list <- list(df1, df2, df3, df4)