[R] as.numeric is truncating!

ticspd harisbilal at gmail.com
Tue Dec 29 22:05:48 CET 2009



ah perfect .. digits = 8 is actually 8 digits TOTAL, not 8 digits after the
decimal point!
setting the default to 15 works for me

thank you!



Berend Hasselman wrote:
> 
> 
> 
> 
> ticspd wrote:
>> 
>> I am trying to convert a string to  a double using "as.numeric"
>> However, R is truncating the results!
>> 
>> Options(digits) is set to 7.
>> 
>> Can anyone shed some light on this?
>> Thanks!
>> > b[1]
>> [1] "116.28125"
>>> summary(b[1])
>>    Length     Class      Mode 
>>         1 character character 
>> 
>>> c <- as.numeric(b[1])
>>> c
>> [1] 116.2812
>> 
> 
> Try the following:
> 
> ?round
> 
> (Note: and look in the Details section).
> 
> as.numeric("116.28135")
> 
> Set options(digits=8) and do the print again.
> 
> R is not truncating; it is following certain rounding rules on printing
> the number given the required
> numbers of digits to show.
> 
> Berend
> 

-- 
View this message in context: http://n4.nabble.com/as-numeric-is-truncating-tp990546p990594.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list