[R] as.numeric is truncating!

2009-12-29 Thread ticspd

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



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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] as.numeric is truncating!

2009-12-29 Thread ticspd


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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] as.numeric is truncating!

2009-12-29 Thread ticspd

thank you.

and for those who didn't get the reference:

http://en.wikipedia.org/wiki/Ren%C3%A9_Magritte
http://en.wikipedia.org/wiki/Ren%C3%A9_Magritte 




Peter Dalgaard wrote:
> 
> 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.dalga...@biostat.ku.dk)  FAX: (+45) 35327907
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.