I was trying to do some contingency tables but I don't know how to pull out the column names when I use mapply function.
This is an example of the data:
set.seed(123) ## for sake of reproducibility
n <- 10
dat <- data.frame(balance=factor(paste("DM", 1:n)),
credit_history=sample(c("repaid", "critical"), 10, replace = TRUE),
purpose=sample(c("yes", "no"), 10, replace = TRUE),
employment_rate=sample(c("0-1 yrs", "1-4 yrs", ">4 yrs"), 10, replace = TRUE),
personal_status=sample(c("married", "single"), 10, replace=TRUE),
other_debtors=sample(c("guarantor", "none"), 10, replace= TRUE),
default=sample(c("yes", "no"), 10, replace = TRUE))
dt1 <- dat[ , c(1:6)]
dt2 <- dat[ , "default"]
mapply(function(x, y) table(x, y), dt1, MoreArgs=list(dt2))
The code above just show "x" and "y" and I would like to display e.g. "default" and "balance". Can someone give me some advice?