data.matrix
Coerce Data Frame to Numeric Matrix

### Description

Takes a data frame as an argument and returns a numeric matrix whose elements correspond to the elements of the data frame.

### Usage

    data.matrix(frame, rownames.force = NA)

### Arguments

frame | a data frame.
rownames.force | a logical value indicating if the row names are forced. If TRUE, the rownames attribute of frame is forced to be used as the row names of the returned matrix. If FALSE, the rownames attribute is always NULL. If NA or any other value, and when the length of rownames of frame is 0, the rownames attribute of the matrix is NULL. Otherwise, the row names of frame are used as the row names of the matrix.

### Details

Integer and other numeric variables are kept with no change. Factors and logical variables are converted to integer using as.integer. Character variables are converted to factors and then to integer. Other non-numeric variables are converted to numeric using as.numeric. The result is an integer or numeric data matrix (can contain NAs).
Value
returns a matrix corresponding to the data frame. The mode and dimensions of the matrix depend on the variables in the data frame.
Differences between Spotfire Enterprise Runtime for R and Open-source R
The function numerical.matrix is not implemented in open-source R.
References
Chambers, J. M. 1992. Data for models. New York, NY: Springer.
Chambers, John M. 1998. Programming with Data. New York, NY: Springer.
Chambers, J. M. and Hastie, T .J. (Eds.) 1992. Chapter 3: Data for Models. Statistical Models in S. Pacific Grove, CA.: Wadsworth & Brooks/Cole.
See Also
as.matrix, data.frame.object, format.default, matrix.
Examples

    head(as.matrix(Sdatasets::fuel.frame))   # produces a character matrix
    head(data.matrix(Sdatasets::fuel.frame)) # factors converted to integer codes
    x_date <- seq(as.POSIXlt("2010-1-1"), as.POSIXlt("2010-5-1"), length.out = 5)
    y_frame <- data.frame(a = x_date, b = c(1:4, NA), c =letters[15:11],
         d = c(NA, TRUE, FALSE, NA,FALSE))
    as.matrix(y_frame)
    data.matrix(y_frame)

Package base version 6.1.5-18
Package Index