From hpages at fhcrc.org  Fri Nov  3 19:50:10 2006
From: hpages at fhcrc.org (Herve Pages)
Date: Fri, 03 Nov 2006 10:50:10 -0800
Subject: [Rd] man page for as.matrix for data frames outdated?
In-Reply-To: <17738.64809.495879.29680@stat.math.ethz.ch>
References: <454AC989.1040002@fhcrc.org>
	<17738.64809.495879.29680@stat.math.ethz.ch>
Message-ID: <454B8F62.3030205@fhcrc.org>

Hi Martin,

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

1) A documentation problem:

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

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

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

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

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

Cheers,

H.



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