[R] subsetting matrix replacement oddities

Martin Maechler maechler at stat.math.ethz.ch
Thu Sep 18 14:56:28 CEST 2003


>>>>> "Spencer" == Spencer Graves <spencer.graves at pdf.com>
>>>>>     on Wed, 17 Sep 2003 17:41:09 -0700 writes:

    Spencer> A subset of a data.frame is still a data.frame.  A
    Spencer> data.frame is actually a list with additional
    Spencer> attributes.  As far as I know, your solution,
    Spencer> "as.matrix", is an appropriate tool to convert a
    Spencer> data.frame to a matrix.  Caution may be
    Spencer> appropropriate, however, because if the data.frame
    Spencer> includes anything not numeric, the result may not
    Spencer> be numeric, and the result is inconsistent between
    Spencer> S-Plus 6.1 and R 1.7.1.  

Yes, using  "as.matrix" is typically not the best, but rather
data.matrix() 
------------  is what you should apply usually to data frames.

(and which is a bit more consistent between R and S-plus).




More information about the R-help mailing list