"as.numeric" / "As.numeric" [was "R-beta: bugs and problems"]
Martin Maechler
maechler at stat.math.ethz.ch
Tue Jun 2 12:02:15 CEST 1998
>>>>> "Jim" == Jim Lindsey <jlindsey at luc.ac.be> writes:
Jim> .....
Jim> 3. To obtain the codes of a factor variable, one uses
Jim> as.numeric(). However, this function destroys the properties of
Jim> the matrix, turning it into a vector.
as.numeric(.) behaves so consistently (also in S-plus);
it has been a `pain' in other situations, such as passing a numeric matrix
to C or Fortran and wanting the result to still be a matrix.
The ``well-known'' (:-) solution is to use
storage.mode(x) <- "numeric"
instead, which is rather clumy, especially when passing arguments to
.C(..).
I've seen
As.numeric <- function(x) { storage.mode(x) <- "numeric"; x }
solving the above problem.
What do you (R-help readers !) think?
Should we add this (and corresponding As.integer, As.character, ....)
to R ?
Or rather use a different function name?
However, not "as.numeric" itself!
For such a basic function, we usually don't want to be unnecessarily
incompatible. User functions written for both R and S should get the same
thing for as.numeric(.).
Martin Maechler <maechler at stat.math.ethz.ch> <><
Seminar fuer Statistik, ETH-Zentrum SOL G1; Sonneggstr.33
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1086
http://www.stat.math.ethz.ch/~maechler/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list