"as.numeric" / "As.numeric" [was "R-beta: bugs and problems"]

Ross Ihaka (ihaka@stat.auckland.ac.nz)
Wed, 3 Jun 1998 10:09:18 +1200 (NZST)


Date: Wed, 3 Jun 1998 10:09:18 +1200 (NZST)
Message-Id: <199806022209.KAA09607@stat1.stat.auckland.ac.nz>
From: Ross Ihaka <ihaka@stat.auckland.ac.nz>
To: Martin Maechler <maechler@stat.math.ethz.ch>
Subject: "as.numeric" / "As.numeric" [was "R-beta: bugs and problems"]
In-Reply-To: <199806021002.MAA00877@sophie.ethz.ch>
 <199806021002.MAA00877@sophie.ethz.ch>

Martin Maechler writes:
 > >>>>> "Jim" == Jim Lindsey <jlindsey@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?

I like the idea, but maybe not the name so much (too much scope for
confusion).  Could I make a plug for something like "mode.numeric" or
"as.numeric.mode".

A single function of the form

	ensure.mode(x, "double")

would be another approach.

	Ross
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._