Coerce Data Frame to Matrix

DESCRIPTION:
This function takes a data frame as an argument and returns a matrix whose elements correspond to the elements of the data frame.

USAGE:
as.matrix.data.frame(x)

REQUIRED ARGUMENTS:
x:
data frame object.

VALUE:
a matrix corresponding to the data frame. The mode and the dimensions of the matrix can depend on the nature of the variables in the data frame.

DETAILS:
Four distinct cases need to be distinguished. First, if all the variables are numeric vectors, the method returns the obvious corresponding numeric matrix. Second, if the variables are a mixture of numeric and factor, the resulting matrix will be of mode "character"; the numeric variables will be converted to character and the factors replaced by the corresponding level values (NA's in factors will be converted to the string "NA"). Third, if any of the variables are not atomic (e.g., of mode "list"), the resulting matrix will be of mode "list". Fourth, if any of the variables are themselves matrices or data frames, they will contribute as many columns as they have to the result (this is independent of the considerations concerning mode discussed above).

This function is a method for the generic function as.matrix for class "data.frame". It can be invoked by calling as.matrix for an object of the appropriate class, or directly by calling as.matrix.data.frame regardless of the class of the object.


SEE ALSO:
as.matrix , data.frame.object , data.matrix , matrix .

EXAMPLES:
as.matrix(fuel.frame) #produces a character matrix
                       Weight Disp. Mileage       Fuel      Type
         Eagle Summit 4 "2560" " 97" "33"    "3.030303" "Small"
        Ford Escort   4 "2345" "114" "33"    "3.030303" "Small"
         Ford Festiva 4 "1845" " 81" "37"    "2.702703" "Small"
          Honda Civic 4 "2260" " 91" "32"    "3.125000" "Small"
        Mazda Protege 4 "2440" "113" "32"    "3.125000" "Small"
                                 .
                                 .
                                 .