Converts data of any kind to numeric values. A factor is expanded to a set of dummy variables.
Vector, factor, matrix or data frame to be converted.
This function converts data (such as a factor) to numeric values in order that the user may calculate, for example, the mean, variance, covariance and correlation of the data.
x is a numeric vector or integer vector, it is returned
x is a logical vector, it is converted to a 0-1 matrix with
2 columns. The first column contains a 1 if the logical value is
FALSE, and the second column contains a 1 if the logical
x is a complex vector, it is converted to a matrix with 2
columns, containing the real and imaginary parts.
x is a factor, the result is a matrix of 0-1 dummy
variables. The matrix has one column for each possible level of the
(i,j) entry is
equal to 1 when the
ith factor value equals the
jth level, and is equal to 0 otherwise.
x is a matrix or data frame, the appropriate conversion is
applied to each column of
Note that, unlike
model.matrix, this command converts a
factor into a full set of dummy variables (one column for each level of
A numeric matrix.
1 2 3 4 5 6 7