[R] rounding problem

tedzzx zengzhenxing at gmail.com
Mon Mar 2 02:51:34 CET 2009


Yes, round(1.5)=2. but round(2.5)=2.  I want round(2.5)=3 just like the what
the excel do.  Can we change the setting or do some trick so that the
computer will work like what we usually do with respect to rounding.
My system is R 2.8.1, winXP, Intel core 2 dual . Thanks. 


Daniel Nordlund-2 wrote:
> 
>> -----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
> 
> ______________________________________________
> R-help at 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://www.nabble.com/rounding-problem-tp22261852p22280785.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list