Skip to content

R-alpha: as.numeric

1 message · Martin Maechler

#
Thomas> as.numeric() turns a logical matrix into a numeric
    Thomas> vector. Shouldn't it stay a matrix?

One first would think so.
However, R here behaves as S.
S> VALUE:
S>        ....
S> 
S>        as.numeric returns a vector like x, but with storage  mode
S>        "double",  if  x  is  a  simple  object of mode "numeric".
S>        Otherwise, as.numeric returns a numeric object of the same
S>        length  as  x  and  with  data resulting from coercing the
S>        elements of x to mode "numeric".

The following shows the old (in S) quite usual ``workaround''.
The following code works `identically' in R and S :
[,1] [,2]
[1,] "1"  "1" 
[2,] "1"  "2" 
[3,] "1"  "3"
[1] 1 1 1 1 2 3
[,1] [,2]
[1,]    1    1
[2,]    1    2
[3,]    1    3
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-