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.
data.matrix(frame, rownames.force = NA)
- a data frame whose components are logical vectors, factors or numeric vectors.
- logical indicating if the resulting matrix should have character (rather than
rownames. The default,
NULLrownames if the data frame has ‘automatic’ row.names or for a zero-row data frame.
Logical and factor columns are converted to integers. Any other column which is not numeric (according to
is.numeric) is converted by
as.numeric or, for S4 objects,
as(, "numeric"). If all columns are integer (after conversion) the result is an integer matrix, otherwise a numeric (double) matrix.
Otherwise, the result of
Chambers, J. M. (1992) Data for models. Chapter 3 of Statistical Models in S eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole.
The default behaviour for data frames differs from R < 2.5.0 which always gave the result character rownames.
Documentation reproduced from R 3.0.1. License: GPL-2.