crosstab | R Documentation |
This function creates a two-way and three-way cross tabulation with absolute frequencies and row-wise, column-wise and total percentages.
crosstab(..., data = NULL, print = c("no", "all", "row", "col", "total"),
freq = TRUE, split = FALSE, na.omit = TRUE, digits = 2, as.na = NULL,
write = NULL, append = TRUE, check = TRUE, output = TRUE)
... |
a matrix or data frame with two or three columns. Alternatively,
an expression indicating the variable names in |
data |
a data frame when specifying one or more variables in the
argument |
print |
a character string or character vector indicating which
percentage(s) to be printed on the console, i.e., no percentages
( |
freq |
logical: if |
split |
logical: if |
na.omit |
logical: if |
digits |
an integer indicating the number of decimal places digits to be used for displaying percentages. |
as.na |
a numeric vector indicating user-defined missing values,
i.e. these values are converted to |
write |
a character string naming a file for writing the output into
either a text file with file extension |
append |
logical: if |
check |
logical: if |
output |
logical: if |
Returns an object of class misty.object
, which is a list with following
entries:
call |
function call |
type |
type of analysis |
data |
matrix or data frame specified in |
args |
specification of function arguments |
result |
list with result tables, i.e., |
Takuya Yanagida takuya.yanagida@univie.ac.at
write.result
, freq
, descript
,
multilevel.descript
, na.descript
.
Rasch, D., Kubinger, K. D., & Yanagida, T. (2011). Statistics in psychology - Using R and SPSS. John Wiley & Sons.
#----------------------------------------------------------------------------
# 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)
## Not run:
# 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")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.