[Rd] man page for as.matrix for data frames outdated?
hpages at fhcrc.org
Fri Nov 3 05:46:01 CET 2006
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.
It's true that "all-logical data frames will be coerced to a logical
> fourLogicals <- 2:5>3
> df1 <- data.frame(a=fourLogicals)
Otherwise it's not true that 'as.matrix' will return a character matrix:
> fourInts <- 2:-1
> df2 <- data.frame(a=fourLogicals, b=fourInts)
> fourDoubles <- rep(pi,4)
> df3 <- data.frame(c=fourDoubles, a=fourLogicals, b=fourInts)
> fourComplexes <- (-1:2)+3i
> df4 <- data.frame(a=fourLogicals, d=fourComplexes, b=fourInts,
If one column is of mode character, then 'as.matrix' will effectively
return a character matrix:
> df5 <- data.frame(toto=c("a","bb"), titi=c(9,999))
Note that the doc says that "any non-numeric/complex column" will
be passed thru 'format' which seems to be exactly the other way
1 "a" " 9"
2 "bb" "999"
Anyway why one would like to have the numeric values passed
thru 'format' to start with?
This is in R-2.4.0 and recent R-devel.
More information about the R-devel