[Rd] man page for as.matrix for data frames outdated?

Martin Maechler maechler at stat.math.ethz.ch
Sat Nov 4 11:27:33 CET 2006


>>>>> "Herve" == Herve Pages <hpages at fhcrc.org>
>>>>>     on Fri, 03 Nov 2006 10:50:10 -0800 writes:

    Herve> Hi Martin,
    Herve> Thanks for the answer!
    Herve> OK I can use data.matrix to convert a data frame to a numeric
    Herve> matrix but that's another story. Basically I'm reporting 2
    Herve> problems with 'as.matrix' when applied to a data frame:

yes, indeed, and I was missing them up partly.

    Herve> 1) A documentation problem:

    Herve> "The method for data frames will convert any
    Herve> non-numeric/complex column into a character vector
    Herve> using 'format'"

    >> df5 <- data.frame(toto=c("a","bb"), titi=c(9,999))
    >> as.matrix(df5)

    Herve> toto titi
    Herve> 1 "a"  "  9"
    Herve> 2 "bb" "999"

    Herve> As I said, it seems to be the other way around: it's not the
    Herve> "non-numeric" column that is converted to a character vector,
    Herve> it's the "numeric" column.

Indeed, and I now agree that the documentation is more wrong
than I first acknowledged.  I'm changing it currently.

    Herve> 2) the questionable decision to do this conversion using 'format'
    Herve> (leading to the addition of unnecessary white space) and not
    Herve> simply 'as.character'

as Bill remarked, 
- there were good reasons pro such a decision,
- to change such decisions without necessity is a problem for
  back-compatibility

    Herve> BTW your mailer seems to do some strange reformatting to the output
    Herve> of my code snippets making it hard to see the "formatting" problem
    Herve> that I'm trying to show.

yes. Part of it was my mistake; sorry.

Best regards to Seattle,
Martin



More information about the R-devel mailing list