# NOT RUN {
dat <- data.frame(x1 = c(1, 2, 2, 1, 1, 2, 2, 1, 1, 2),
x2 = c(1, 2, 2, 1, 2, 1, 1, 1, 2, 1),
x3 = c(-99, 2, 1, 1, 1, 2, 2, 2, 2, 1))
# Cross Tabulation for x1 and x2
crosstab(dat[, c("x1", "x2")])
# Cross Tabulation for x1 and x2
# print all percentages
crosstab(dat[, c("x1", "x2")], print = "all")
# Cross Tabulation for x1 and x2
# print row-wise percentages
crosstab(dat[, c("x1", "x2")], print = "row")
# Cross Tabulation for x1 and x2
# print col-wise percentages
crosstab(dat[, c("x1", "x2")], print = "col")
# Cross Tabulation x1 and x2
# print total percentages
crosstab(dat[, c("x1", "x2")], print = "total")
# Cross Tabulation for x1 and x2
# print all percentages, split output table
crosstab(dat[, c("x1", "x2")], print = "all", split = TRUE)
# Cross Tabulation for x1 and x3
# do not apply listwise deletion, convert value -99 to NA
crosstab(dat[, c("x1", "x3")], na.omit = FALSE, as.na = -99)
# Cross Tabulation for x1 and x3
# print all percentages, do not apply listwise deletion, convert value -99 to NA
crosstab(dat[, c("x1", "x3")], print = "all", na.omit = FALSE, as.na = -99)
# Cross Tabulation for x1, x2, and x3
crosstab(dat[, c("x1", "x2", "x3")])
# Cross Tabulation for x1, x2, and x3
# print all percentages
crosstab(dat[, c("x1", "x2", "x3")], print = "all")
# Cross Tabulation for x1, x2, and x3
# print all percentages, split output table
crosstab(dat[, c("x1", "x2", "x3")], print = "all", split = TRUE)
# }
# NOT RUN {
# Write Results into a Excel file
result <- crosstab(dat[, c("x1", "x2")], print = "all", output = FALSE)
write.result(result, "Crosstab.xlsx")
# }
Run the code above in your browser using DataLab