% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/fxtabs.R
\name{fxtabs}
\alias{fxtabs}
\title{Perfectly Flat Cross Table by native xtabs}
\usage{
fxtabs(
  formula = ~.,
  data = parent.frame(),
  subset,
  sparse = FALSE,
  na.action,
  na.rm = FALSE,
  addNA = FALSE,
  exclude = if (!addNA) c(NA, NaN),
  drop.unused.levels = FALSE,
  remove_zeros = 0,
  print = 0,
  debug = 0
)
}
\arguments{
\item{formula}{a formula object of the form lhs~rhs}

\item{data}{an optional data frame containing the variables in
the formula formula.}

\item{subset}{xtabs parameter}

\item{sparse}{xtabs parameter}

\item{na.action}{xtabs parameter}

\item{na.rm}{xtabs parameter}

\item{addNA}{xtabs parameter}

\item{exclude}{xtabs parameter}

\item{drop.unused.levels}{xtabs parameter}

\item{remove_zeros}{= 1 to remove zero frequency cells}

\item{print}{= 1 to print the result}

\item{debug}{= 1 to print the intermediate results}
}
\value{
a matrix of flat contingency table.
}
\description{
This function makes the result of xtabs perfectly flat.
}
\details{
\code{formula} and \code{data} parameters function the same way
as native xtab function. \cr
In addtion, those parameters marked as "xtabs parameter",
see \link[stats:xtabs]{stats::xtabs}.

The core part of thus function is as follows:
\preformatted{
 res <- ftable( xtabs( lhs~rhs,  data=data ) )
}
The above returns a matrix when \code{lhs} is a matrix.
However, as shown in the examples,
when \code{lhs} is a vector or missing, the result is a cross table. \cr
Note that, by adjusting \code{row.vars} and \code{col.vars} options of
 \code{ftable}, it is possible to produce a completely flat table.
}
\examples{

seed=1701
set.seed(seed)
n <- 50
x1 <- sample(1:3,n,replace=TRUE)
x2 <- sample(LETTERS[1:2],n,replace=TRUE)
x3 <- sample(letters[1:2],n,replace=TRUE)
c1 <- sample(c(0:3),n,replace=TRUE)
c2 <- sample(c(0:5),n,replace=TRUE)
data=data.frame(x1,x2,c1,c2)

# 3 by variables
fxtabs( cbind(c1,c2)~x1+x2+x3, data=data)
ftable(xtabs( cbind(c1,c2)~x1+x2+x3, data=data))
fxtabs( c1~x1+x2+x3, data=data)
ftable(xtabs( c1~x1+x2+x3, data=data))
fxtabs( ~x1+x2+x3, data=data)
ftable(xtabs( ~x1+x2+x3, data=data))

# 2 by variables
fxtabs( cbind(c1,c2)~x1+x2, data=data)
ftable(xtabs( cbind(c1,c2)~x1+x2, data=data))
fxtabs( c1~x1+x2, data=data)
ftable(xtabs( c1~x1+x2, data=data))
fxtabs( ~x1+x2, data=data)
ftable(xtabs( ~x1+x2, data=data))

# single by variable
fxtabs( cbind(c1,c2)~x1, data=data)
ftable(xtabs( cbind(c1,c2)~x1, data=data))
fxtabs( c1~x1, data=data)
ftable(xtabs( c1~x1, data=data))
fxtabs( ~x1, data=data)
ftable(xtabs( ~x1, data=data))


}
