>>>>> "Herve" == Herve Pages <[EMAIL PROTECTED]>
>>>>>     on Thu, 02 Nov 2006 20:46:01 -0800 writes:

    Herve> Hi again, The man page for 'as.matrix' says:

   >>      'as.matrix' is a generic function. The method
   >> for data frames will convert any non-numeric/complex
   >> column into a character vector using 'format' and so
   >> return a character matrix, except that all-logical
   >> data frames will be coerced to a logical matrix.

In very old versions of R (e.g. 0.3 from March 1996),

    is.numeric(<logical>)  was TRUE
and there the help page was entirely correct.

I think if you replace [in the above paragraph]
    "non-numeric/complex"
by  "non-(logical/numeric/complex)"

the help page is correct again.


    Herve> If one column is of mode character, then 'as.matrix'
    Herve> will effectively return a character matrix:

(as it says in the man page, and always did in all
 implementations of the S language)

    Herve> Note that the doc says that "any non-numeric/complex
    Herve> column" will be passed thru 'format' which seems to
    Herve> be exactly the other way around:

No!  You left off the second part of the statement cited initally.
Slightly reformulated:

         Iff there's any non-(logical/numeric/complex) column,
         that will have to be passed through format and hence
         the result must be a character matrix 
         and hence every other column also needs to be "formatted"


    >> as.matrix(df5)
    Herve>       toto titi 1 "a" " 9" 2 "bb" "999"

    Herve> Anyway why one would like to have the numeric values
    Herve> passed thru 'format' to start with?

Recall: The result must be a matrix !
        If it can't be a numeric matrix the decision was it must
        be character.

BTW: Exactly because of your problems,  
     The function   data.matrix()  had been devised (long ago in
     pre-R times),
     and data.matrix  *is*  the first entry in "See Also" on the
     help page for as.matrix

Martin

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to