Dat <- esoph[, 1:3]
library(tidyverse)
library(broom)
data.frame(t(combn(names(Dat),2)), stringsAsFactors = F) %>%
mutate(d = map2(X1, X2, ~tidy(chisq.test(Dat[,.x], Dat[,.y])))) %>%
unnest()
# X1 X2 statistic p.value parameter method
# 1 agegp alcgp 1.4189096 0.9999971 15 Pearson's Chi-squared test
# 2 agegp tobgp 2.4000000 0.9999022 15 Pearson's Chi-squared test
# 3 alcgp tobgp 0.6194617 0.9999240 9 Pearson's Chi-squared test