\HeaderA{ftable.formula}{Formula Notation for Flat Contingency Tables}{ftable.formula}
\keyword{category}{ftable.formula}
\begin{Description}\relax
Produce or manipulate a flat contingency table using
formula notation.
\end{Description}
\begin{Usage}
\begin{verbatim}
## S3 method for class 'formula':
ftable(formula, data = NULL, subset, na.action, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{formula}] a formula object with both left and right hand sides
specifying the column and row variables of the flat table.
\item[\code{data}] a data frame, list or environment (or similar: see
\code{\LinkA{model.frame}{model.frame}}) containing the variables
to be cross-tabulated, or a contingency table (see below).
\item[\code{subset}] an optional vector specifying a subset of observations
to be used.
Ignored if \code{data} is a contingency table.
\item[\code{na.action}] a function which indicates what should happen when
the data contain \code{NA}s.
Ignored if \code{data} is a contingency table.
\item[\code{...}] further arguments to the default ftable method may also
be passed as arguments, see \code{\LinkA{ftable.default}{ftable.default}}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
This is a method of the generic function \code{\LinkA{ftable}{ftable}}.

The left and right hand side of \code{formula} specify the column and
row variables, respectively, of the flat contingency table to be
created.  Only the \code{+} operator is allowed for combining the
variables.  A \code{.} may be used once in the formula to indicate
inclusion of all the remaining variables.

If \code{data} is an object of class \code{"table"} or an array with
more than 2 dimensions, it is taken as a contingency table, and hence
all entries should be nonnegative.  Otherwise, if it is not a flat
contingency table (i.e., an object of class \code{"ftable"}), it
should be a data frame or matrix, list or environment containing the
variables to be cross-tabulated.  In this case, \code{na.action} is
applied to the data to handle missing values, and, after possibly
selecting a subset of the data as specified by the \code{subset}
argument, a contingency table is computed from the variables.

The contingency table is then collapsed to a flat table, according to
the row and column variables specified by \code{formula}.
\end{Details}
\begin{Value}
A flat contingency table which contains the counts of each combination
of the levels of the variables, collapsed into a matrix for suitably
displaying the counts.
\end{Value}
\begin{SeeAlso}\relax
\code{\LinkA{ftable}{ftable}},
\code{\LinkA{ftable.default}{ftable.default}};
\code{\LinkA{table}{table}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
Titanic
x <- ftable(Survived ~ ., data = Titanic)
x
ftable(Sex ~ Class + Age, data = x)
\end{ExampleCode}
\end{Examples}

