[R] help on data frame and matrix

Martin Maechler maechler at stat.math.ethz.ch
Mon Sep 18 08:52:55 CEST 2006


>>>>> "John" == John Kane <jrkrideau at yahoo.ca>
>>>>>     on Sun, 17 Sep 2006 12:10:19 -0400 (EDT) writes:

    John> --- Finosaur <mouandny at gmail.com> wrote:

    >> I am given a data frame, which actually contains a
    >> matrix. But I need to convert the data frame into a
    >> matrix so that I can use the matrix operators. Can
    >> anybody help me out? Thanks a lot.
    >> 
    >> 
    >> Thaleia

    John>  d <- as.matrix(data.frame)

It's (almost always) better to use Dimitri's suggestion,
data.matrix(), since that also produces a numeric matrix when
the data frame contains factors.

Martin



More information about the R-help mailing list