Re: [Rd] AS_NUMERIC and as.numeric - Could someone explain?

From: Simon Urbanek <simon.urbanek_at_math.uni-augsburg.de>
Date: Fri 02 Jul 2004 - 03:28:20 EST

On Jul 1, 2004, at 6:09 AM, Douglas Bates wrote:

> AS_NUMERIC in C more closely corresponds to as.double() in R
>
> All that as.numeric() in R does is assure that the result is of a
> numeric mode. It does not coerce integer variables to doubles.

Um... are you sure?? For the sake of lots of code I saw I hope you're wrong:

> Check, for example,
> str(as.numeric(1:100))

Yes:

 > str(as.double(1:10))
  num [1:10] 1 2 3 4 5 6 7 8 9 10
 > str(as.numeric(1:10))

  num [1:10] 1 2 3 4 5 6 7 8 9 10
 > str(1:10)
  int [1:10] 1 2 3 4 5 6 7 8 9 10

And moreover:

 > as.numeric
function (x, ...)
UseMethod("as.double")
<environment: namespace:base>

... admittedly I didn't answer the original question, but I suspect that the problem lies somewhere else ...

Simon



R-devel@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-devel Received on Fri Jul 02 03:31:46 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 08:59:06 EST