[R] round() seems inconsistent when rounding 5s
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Sun Mar 16 02:28:34 CET 2003
Rashid Nassar <rnassar at duke.edu> writes:
> Many thanks to all for the very quick replies. I should have stated the
> apparent problem more clearly: round() does not seem to always round 5 to
> the nearest even value as I expected, as my examples (repeated below)
> > round(2.45, 1)
>  2.5 # shouldn't this be 2.4?
> > round(1.05, 1)
>  1.1 # 1.0 ?
> > signif(3.445, 3)
>  3.45 # 3.44 ?
> Apologies for not stating this more clearly in my first message, and again
> thanks for the replies.
Yes. From my reading of the code, I would expect 2.4 in the first case
as well. It appears that the intention is to subtract off the integer
part, scale according to the number of digits and round nnn.5 +- eps
towards even values of nnn, but that's not what is happening.
Anyone want to trace through the code and see what is going on?
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help