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

From: Martin Maechler <>
Date: Fri 03 Nov 2006 - 08:26:17 GMT

>>>>> "Herve" == Herve Pages <> >>>>> 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]

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 mailing list Received on Fri Nov 03 21:30:13 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 03 Nov 2006 - 19:31:18 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.