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

Ross Ihaka ihaka at stat.auckland.ac.nz
Wed Jun 3 00:09:18 CEST 1998

Martin Maechler writes:
 > >>>>> "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?

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

A single function of the form

	ensure.mode(x, "double")

would be another approach.

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