educ <- sample(c(1, 2), 200, replace = TRUE, prob = c(0.3, 0.7))
educ <- factor(educ, levels = c(1, 2), labels = c("Low", "High"))
income <- sample(c(1, 2, 3), 200, replace = TRUE,
prob = c(0.3, 0.4, 0.3))
income <- factor(income, levels = c(1, 2, 3),
labels = c("Low", "Middle", "High"))
attr(educ, "label") <- "Education level"
attr(income, "label") <- "Income level"
w <- sample(c(10, 15, 19), 200, replace = TRUE)
crosstab(income, educ, ylab = "Education", xlab = "Income")
ct <- crosstab(income, educ, w, expected = TRUE, plot = FALSE)
ct
plot(ct, inv.y = TRUE)
print(xtable(ct))
print(xtable(ct, decimal.mark = ",", digits = 1,
multirow = TRUE, hline = TRUE, align = "llrrr"),
sanitize.text.function = function(x) x,
include.rownames = FALSE)
Run the code above in your browser using DataLab