[R] as.numeric is truncating!

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Dec 30 01:59:49 CET 2009


ticspd wrote:
> I am trying to convert a string to  a double using "as.numeric"
> However, R is truncating the results!

No it isn't! As someone phrased it recently, there's a difference 
between an object and the display of an object. "Ceci n'est pas une pipe".

> Options(digits) is set to 7.

So numbers are _printed_ to 7-digit accuracy, yes. (And 116.28125 has 8 
digits.)

> Can anyone shed some light on this?

Subtract 116, and enlightenment should follow.


> Thanks!
> 
> 
>> b[1]
> [1] "116.28125"
> 
>> summary(b[1])
>    Length     Class      Mode 
>         1 character character 
> 
>> c <- as.numeric(b[1])
>> c
> [1] 116.2812
> 
> 
> 


-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list