[R] Converting the columns of a data frame to numeric

Martin Maechler maechler at stat.math.ethz.ch
Mon Sep 2 15:36:00 CEST 2002


>>>>> "Daniel" == Daniel Mastropietro <mastropi at uwalumni.com>
>>>>>     on Sun, 01 Sep 2002 16:35:29 -0300 writes:

    Daniel> Hello, I have a data frame whose columns are factors
    Daniel> with numeric levels and I want to convert the
    Daniel> columns to numeric so that I can treat the data
    Daniel> frame as a matrix.  I found a way of doing this but
    Daniel> would like to know if there is an easier way.

    Daniel> My way is:

    Daniel> M <- matrix(ncol=ncol(df), nrow=nrow(df), as.numeric(as.matrix(df)))

    Daniel> where 'df' is the data frame.

Would
	M <- data.matrix(df)

solve your problem?  I think it is intended to.
Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list