Accepts a data frame as input and computes a contingency table for direct use in combination with the magrittr package.
categorize(.data, ...)
A table (possibly as an xtabs class if a model formula was used)
categorize is a wrapper to xtabs or table such that a data frame can be given as the first argument.
if (requireNamespace("magrittr", quietly = TRUE)) {
library(magrittr)
esoph %>% categorize(alcgp, agegp)
esoph %>% categorize(~ alcgp + agegp)
}
#> agegp
#> alcgp 25-34 35-44 45-54 55-64 65-74 75+
#> 0-39g/day 4 4 4 4 4 3
#> 40-79 4 4 4 4 3 4
#> 80-119 3 4 4 4 4 2
#> 120+ 4 3 4 4 4 2