\HeaderA{as.data.frame}{Coerce to a Data Frame}{as.data.frame}
\methaliasA{as.data.frame.array}{as.data.frame}{as.data.frame.array}
\methaliasA{as.data.frame.AsIs}{as.data.frame}{as.data.frame.AsIs}
\methaliasA{as.data.frame.character}{as.data.frame}{as.data.frame.character}
\methaliasA{as.data.frame.complex}{as.data.frame}{as.data.frame.complex}
\methaliasA{as.data.frame.data.frame}{as.data.frame}{as.data.frame.data.frame}
\methaliasA{as.data.frame.default}{as.data.frame}{as.data.frame.default}
\methaliasA{as.data.frame.difftime}{as.data.frame}{as.data.frame.difftime}
\methaliasA{as.data.frame.factor}{as.data.frame}{as.data.frame.factor}
\methaliasA{as.data.frame.integer}{as.data.frame}{as.data.frame.integer}
\methaliasA{as.data.frame.list}{as.data.frame}{as.data.frame.list}
\methaliasA{as.data.frame.logical}{as.data.frame}{as.data.frame.logical}
\methaliasA{as.data.frame.matrix}{as.data.frame}{as.data.frame.matrix}
\methaliasA{as.data.frame.model.matrix}{as.data.frame}{as.data.frame.model.matrix}
\methaliasA{as.data.frame.numeric}{as.data.frame}{as.data.frame.numeric}
\methaliasA{as.data.frame.ordered}{as.data.frame}{as.data.frame.ordered}
\methaliasA{as.data.frame.raw}{as.data.frame}{as.data.frame.raw}
\methaliasA{as.data.frame.ts}{as.data.frame}{as.data.frame.ts}
\methaliasA{as.data.frame.vector}{as.data.frame}{as.data.frame.vector}
\aliasA{is.data.frame}{as.data.frame}{is.data.frame}
\keyword{classes}{as.data.frame}
\keyword{methods}{as.data.frame}
\begin{Description}\relax
Functions to check if an object is a data frame, or coerce it if possible.
\end{Description}
\begin{Usage}
\begin{verbatim}
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
## S3 method for class 'character':
as.data.frame(x, ...,
              stringsAsFactors = default.stringsAsFactors())
## S3 method for class 'matrix':
as.data.frame(x, row.names = NULL, optional = FALSE, ..., 
              stringsAsFactors = default.stringsAsFactors())

is.data.frame(x)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] any \R{} object.
\item[\code{row.names}] \code{NULL} or a character vector giving the row
names for the data frame.  Missing values are not allowed.
\item[\code{optional}] logical. If \code{TRUE}, setting row names and
converting column names (to syntactic names: see
\code{\LinkA{make.names}{make.names}}) is optional.
\item[\code{...}] additional arguments to be passed to or from methods.
\item[\code{stringsAsFactors}] logical: should the character vector be converted
to a factor?
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{as.data.frame} is a generic function with many methods, and
users and packages can supply further methods.

If a list is supplied, each element is converted to a column in the
data frame.  Similarly, each column of a matrix is converted separately.
This can be overridden if the object has a class which has
a method for \code{as.data.frame}: two examples are
matrices of class \code{"\LinkA{model.matrix}{model.matrix}"} (which are
included as a single column) and list objects of class
\code{"\LinkA{POSIXlt}{POSIXlt}"} which are coerced to class
\code{"\LinkA{POSIXct}{POSIXct}"}.

Arrays can be converted to data frames.  One-dimensional arrays are
treated like vectors and two-dimensional arrays like matrices.  Arrays
with more than two dimensions are converted to matrices by
\sQuote{flattening} all dimensions after the first and creating
suitable column labels.

Character variables are converted to factor columns unless protected
by \code{\LinkA{I}{I}}.

If a data frame is supplied, all classes preceding \code{"data.frame"}
are stripped, and the row names are changed if that argument is supplied.

If \code{row.names = NULL}, row names are constructed from the names
or dimnames of \code{x}, otherwise are the integer sequence
starting at one.  Few of the methods check for duplicated row names.
Names are removed from vector columns unless \code{\LinkA{I}{I}}.
\end{Details}
\begin{Value}
\code{as.data.frame} returns a data frame, normally with all row names
\code{""} if \code{optional = TRUE}.

\code{is.data.frame} returns \code{TRUE} if its argument is a data
frame (that is, has \code{"data.frame"} amongst its classes)
and \code{FALSE} otherwise.
\end{Value}
\begin{References}\relax
Chambers, J. M. (1992)
\emph{Data for models.}
Chapter 3 of \emph{Statistical Models in S}
eds J. M. Chambers and T. J. Hastie, Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{data.frame}{data.frame}}, \code{\LinkA{as.data.frame.table}{as.data.frame.table}} for the
\code{table} method (which has additional arguments if called directly).
\end{SeeAlso}

