#----------------------------------------------------------------------------
# Two-Dimensional Table
# Example 1a: Cross Tabulation for 'vs' and 'am'
crosstab(mtcars[, c("vs", "am")])
# Example 1b: Alternative specification using the 'data' argument
crosstab(vs, am, data = mtcars)
# Example 2: Cross Tabulation, print all percentages
crosstab(mtcars[, c("vs", "am")], print = "all")
# Example 3: Cross Tabulation, print row-wise percentages
crosstab(mtcars[, c("vs", "am")], print = "row")
# Example 4: Cross Tabulation, print col-wise percentages
crosstab(mtcars[, c("vs", "am")], print = "col")
# Example 5: Cross Tabulation, print total percentages
crosstab(mtcars[, c("vs", "am")], print = "total")
# Example 6: Cross Tabulation, print all percentages, split output table
crosstab(mtcars[, c("vs", "am")], print = "all", split = TRUE)
#----------------------------------------------------------------------------
# Three-Dimensional Table
# Example 7a: Cross Tabulation for 'vs', 'am', ane 'gear'
crosstab(mtcars[, c("vs", "am", "gear")])
# Example 7b: Alternative specification using the 'data' argument
crosstab(vs:gear, data = mtcars)
# Example 8: Cross Tabulation, print all percentages
crosstab(mtcars[, c("vs", "am", "gear")], print = "all")
# Example 9: Cross Tabulation, print all percentages, split output table
crosstab(mtcars[, c("vs", "am", "gear")], print = "all", split = TRUE)
if (FALSE) {
# Example 10a: Write results into a text file
crosstab(mtcars[, c("vs", "am")], print = "all", write = "Crosstab.txt")
# Example 10b: Write results into an Excel file
crosstab(mtcars[, c("vs", "am")], print = "all", write = "Crosstab.xlsx")
result <- crosstab(mtcars[, c("vs", "am")], print = "all", output = FALSE)
write.result(result, "Crosstab.xlsx")
}
Run the code above in your browser using DataLab