[R] rounding problem

Daniel Nordlund djnordlund at verizon.net
Sun Mar 1 10:15:47 CET 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of tedzzx
> Sent: Saturday, February 28, 2009 4:58 AM
> To: r-help at r-project.org
> Subject: [R] rounding problem
> 
> 
> Hi all,
> 
> According to the help page on round(), round(1.5) could be 
> either 1 or 2.
> But I want to the answere to be 2 for sure just what we 
> usually do. How can
> I do that? Thanks advance.
> 
> Cheers
> 
> Ted
> -- 

Ted,

Actually, the documentation (at least for R-2.8.1) doesn't say that.  The
number 1.5 can be represented exactly on most systems that I know, and
therefore it will round to the even digit, i.e. round(1.5) = 2.0 .  The
documentation says that 0.15 cannot be represented exactly, and therefore
whether it rounds to 0.1 or 0.2 depends on the OS and the machine
architecture.  So on my WinXP Pentium IV system, 1.5 rounds to 2.0 and it
also happens that round(0.15, 1) equals 0.2  .  You say you want 1.5 to
round to 2.0.  What would you like the result of round(2.5) to equal?

Dan

Daniel Nordlund
Bothell, WA USA




More information about the R-help mailing list