% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/crosstab.R
\name{crosstab}
\alias{crosstab}
\title{Cross Tabulation}
\usage{
crosstab(data, ..., 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)
}
\arguments{
\item{data}{a data frame with two or three columns.}

\item{...}{an expression indicating the variable names in \code{data}, e.g.,
\code{crosstab(dat, x1, x2, x3)}. Note that the operators
\code{+}, \code{-}, \code{~}, \code{:}, \code{::},
and \code{!} can also be used to select variables, see 'Details'
in the \code{\link{df.subset}} function.}

\item{print}{a character string or character vector indicating which
percentage(s) to be printed on the console, i.e., no percentages
(\code{"no"}) (default), all percentages (\code{"all"}),
row-wise percentages (\code{"row"}), column-wise percentages
(\code{"col"}), and total percentages (\code{"total"}).}

\item{freq}{logical: if \code{TRUE} (default), absolute frequencies will be included
in the cross tabulation.}

\item{split}{logical: if \code{TRUE}, output table is split in absolute
frequencies and percentage(s).}

\item{na.omit}{logical: if \code{TRUE} (default), incomplete cases are removed before
conducting the analysis (i.e., listwise deletion).}

\item{digits}{an integer indicating the number of decimal places digits
to be used for displaying percentages.}

\item{as.na}{a numeric vector indicating user-defined missing values,
i.e. these values are converted to \code{NA} before conducting
the analysis.}

\item{write}{a character string naming a file for writing the output into
either a text file with file extension \code{".txt"} (e.g.,
\code{"Output.txt"}) or Excel file with file extension
\code{".xlsx"}  (e.g., \code{"Output.xlsx"}). If the file
name does not contain any file extension, an Excel file will
be written.}

\item{append}{logical: if \code{TRUE} (default), output will be appended
to an existing text file with extension \code{.txt} specified
in \code{write}, if \code{FALSE} existing text file will be
overwritten.}

\item{check}{logical: if \code{TRUE} (default), argument specification is checked.}

\item{output}{logical: if \code{TRUE} (default), output is printed on the console.}
}
\value{
Returns an object of class \code{misty.object}, which is a list with following
entries:
  \item{\code{call}}{function call}
  \item{\code{type}}{type of analysis}
  \item{\code{data}}{data frame specified in \code{data}}
  \item{\code{args}}{specification of function arguments}
  \item{\code{result}}{list with result tables, i.e., \code{crosstab} for the
                       cross tabulation, \code{freq.a} for the absolute frequencies,
                       \code{perc.r} for the row-wise percentages, \code{perc.c}
                       for the column-wise percentages, \code{perc.t} for the total
                       percentages}
}
\description{
This function creates a two-way and three-way cross tabulation with absolute
frequencies and row-wise, column-wise and total percentages.
}
\examples{
#————————————————————————————————————————————————————————————————————————————
# Two-Dimensional Table

# Example 1a: Cross Tabulation for 'vs' and 'am'
crosstab(mtcars, vs, am)

# Alternative specification without using the '...' argument
crosstab(mtcars[, c("vs", "am")])

# Example 1b: Cross Tabulation, print all percentages
crosstab(mtcars, vs, am, print = "all")

# Example 1c: Cross Tabulation, print row-wise percentages
crosstab(mtcars, vs, am, print = "row")

# Example 1d: Cross Tabulation, print col-wise percentages
crosstab(mtcars, vs, am, print = "col")

# Example 1e: Cross Tabulation, print all percentages, split output table
crosstab(mtcars, vs, am, print = "all", split = TRUE)

#————————————————————————————————————————————————————————————————————————————
# Three-Dimensional Table

# Example 2a: Cross Tabulation for 'vs', 'am', ane 'gear'
crosstab(mtcars, vs:gear)

# Alternative specification without using the '...' argument
crosstab(mtcars[, c("vs", "am", "gear")])

# Example 2b: Cross Tabulation, print all percentages
crosstab(mtcars, vs:gear, print = "all")

# Example 2c: Cross Tabulation, print all percentages, split output table
crosstab(mtcars, vs:gear, print = "all", split = TRUE)

\dontrun{
#————————————————————————————————————————————————————————————————————————————
# Write Results

# Example 3a: Write Results into a text file
crosstab(mtcars, vs:gear, print = "all", write = "Crosstab.txt")

# Example 3b: Write Results into an Excel file
crosstab(mtcars, vs:gear, print = "all", write = "Crosstab.xlsx")
}
}
\references{
Rasch, D., Kubinger, K. D., & Yanagida, T. (2011). \emph{Statistics in psychology
- Using R and SPSS}. John Wiley & Sons.
}
\author{
Takuya Yanagida \email{takuya.yanagida@univie.ac.at}

\code{\link{write.result}}, \code{\link{freq}}, \code{\link{descript}},
\code{\link{multilevel.descript}}, \code{\link{na.descript}}.
}
