[R] data.matrix output is not numeric

Ed Siefker ebs15242 at gmail.com
Fri Oct 13 20:07:59 CEST 2017

I have a data frame full of integer values.  I need a matrix full of
numeric values.

?data.matrix reads:

     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.

This does not work.

test.df <- data.frame(a=as.integer(c(1,2,3)), b=as.integer(c(4,5,6)))
> class(test.df[[1,1]])
[1] "integer"
> class(data.matrix(test.df)[[1]])
[1] "integer"

What's going on here?

More information about the R-help mailing list