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 <- rnorm(200, 1000, 100) + 100 * as.numeric(educ)
attr(educ, "label") <- "Education level"
attr(income, "label") <- "Income"
w <- sample(c(10, 15, 19), 200, replace = TRUE)
compmeans(income, educ, col = c("#FFD0E0", "#D8E8FF"))
comp <- compmeans(income, educ, w, plot = FALSE)
comp
plot(comp)
print(xtable(comp))
# If the decimal separator in your country is a comma:
# options(OutDec = ",")
print(xtable(comp, align = "lrrr", display = c("s", "f", "d", "f")))
Run the code above in your browser using DataLab