\HeaderA{data.matrix}{Convert a Data Frame to a Numeric Matrix}{data.matrix}
\keyword{array}{data.matrix}
\begin{Description}\relax
Return the matrix obtained by converting all the variables in a data
frame to numeric mode and then binding them together as the columns of
a matrix.  Factors and ordered factors are replaced by their internal
codes.
\end{Description}
\begin{Usage}
\begin{verbatim}
data.matrix(frame, rownames.force = NA)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{frame}] a data frame whose components are logical vectors,
factors or numeric vectors.
\item[\code{rownames.force}] logical indicating if the resulting matrix
should have character (rather than \code{NULL})
\code{\LinkA{rownames}{rownames}}.  The default, \code{NA}, uses \code{NULL}
rownames if the data frame has \sQuote{automatic} row.names or for a
zero-row data frame.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Logical and factor columns are converted to integers.  Any other
column which is not numeric (according to \code{\LinkA{is.numeric}{is.numeric}}) is
converted by \code{\LinkA{as.numeric}{as.numeric}} or, for S4 objects,
\code{\LinkA{as}{as}(, "numeric")}.  If all columns are integer (after
conversion) the result is an integer natrix, otherwise a numeric
(double) matrix.
\end{Details}
\begin{Value}
If \code{frame} inherits from class \code{"data.frame"}, an integer or
numeric matrix of the same dimensions as \code{frame}, with dimnames
taken from the \code{row.names} (or \code{NULL}, depending on
\code{rownames.force}) and \code{names}.

Otherwise, the result of \code{\LinkA{as.matrix}{as.matrix}}.
\end{Value}
\begin{Note}\relax
The default behaviour for data frames differs from \R{} < 2.5.0 which
always gave the result character rownames.
\end{Note}
\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{as.matrix}{as.matrix}},
\code{\LinkA{data.frame}{data.frame}},
\code{\LinkA{matrix}{matrix}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
DF <- data.frame(a=1:3, b=letters[10:12],
                 c=seq(as.Date("2004-01-01"), by = "week", len = 3),
                 stringsAsFactors = TRUE)
data.matrix(DF[1:2])
data.matrix(DF)
\end{ExampleCode}
\end{Examples}

