Hi, I am getting some strange results using round - it seems that it depends if the number before the decimal point is odd or even .... For example:> round(1.5)[1] 2> round(2.5)[1] 2While i would expect that round(2.5) be 3 and not 2. Do you have any explanation for that? I really appreciate your input, Monica _________________________________________________________________ [[trailing spam removed]] [[alternative HTML version deleted]]
On Thu, 2 Aug 2007, Monica Pisica wrote:> > Hi, > > I am getting some strange results using round - it seems that it depends if > the number before the decimal point is odd or even ....Yes. This is explained in the help page for round(). -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle
Monica Pisica wrote:> Hi, > > I am getting some strange results using round - it seems that it depends if the number before the decimal point is odd or even .... > > For example: > > >> round(1.5)[1] 2> round(2.5)[1] 2 >> > While i would expect that round(2.5) be 3 and not 2. > > Do you have any explanation for that? > >http://www.google.com/search?q="round+to+even"
On Thu, 2 Aug 2007, Monica Pisica wrote:> > Hi, > > I am getting some strange results using round - it seems that it depends if the number before the decimal point is odd or even .... > > For example: > > > round(1.5)[1] 2> round(2.5)[1] 2 > While i would expect that round(2.5) be 3 and not 2. > > Do you have any explanation for that?Yes: you obviously did not read the man page! Please do. Z> I really appreciate your input, > > Monica > > > _________________________________________________________________ > [[trailing spam removed]] > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > >
That is what it is supposed to do. From ?round we get "Note that for rounding off a 5, the IEC 60559 standard is expected to be used, ?go to the even digit?. Therefore round(0.5) is 0 and round(-1.5) is -2. However, this is dependent on OS services and on representation error (since e.g. 0.15 is not represented exactly, the rounding rule applies to the represented number and not to the printed number, and so round(0.15, 1) could be either 0.1 or 0.2). " Monica Pisica wrote:> Hi, > > I am getting some strange results using round - it seems that it depends if the number before the decimal point is odd or even .... > > For example: > >> round(1.5)[1] 2> round(2.5)[1] 2 > While i would expect that round(2.5) be 3 and not 2. > > Do you have any explanation for that? > > I really appreciate your input, > > Monica > > > _________________________________________________________________ > [[trailing spam removed]] > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >-- David C. Howell PO Box 770059 627 Meadowbrook Circle Steamboat Springs, CO 80477
Hi again, Mea culpa for not reading help pages before hand - but one would not go there when the function syntax is obvious and known .... besides other programming languages (for example IDL) with same function do not round to the next even number .... so i do get 3 for round(2.5), and i didn't realize that it is "normal" for R to give a 2 instead of 3.> Date: Thu, 2 Aug 2007 22:38:49 +0200> From: Achim.Zeileis@wu-wien.ac.at> To: pisicandru@hotmail.com> CC: r-help@stat.math.ethz.ch> Subject: Re: [R] - round() strange behaviour> > On Thu, 2 Aug 2007, Monica Pisica wrote:> > >> > Hi,> >> > I am getting some strange results using round - it seems that it depends if the number before the decimal point is odd or even ....> >> > For example:> >> > > round(1.5)[1] 2> round(2.5)[1] 2> > While i would expect that round(2.5) be 3 and not 2.> >> > Do you have any explanation for that?> > Yes: you obviously did not read the man page! Please do.> Z> > > I really appreciate your input,> >> > Monica> >> >> > _________________________________________________________________> > [[trailing spam removed]]> >> > [[alternative HTML version deleted]]> >> > ______________________________________________> > R-help@stat.math.ethz.ch 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.> >> >> _________________________________________________________________ Messenger Café — open for fun 24/7. Hot games, cool activities served daily. Visit now. [[alternative HTML version deleted]]
On 2 Aug 2007 at 20:16, Monica Pisica wrote:> > Hi, > > I am getting some strange results using round - it seems that it depends if the number before the decimal point is odd or even .... > > For example: > > > round(1.5)[1] 2> round(2.5)[1] 2 > While i would expect that round(2.5) be 3 and not 2. > > Do you have any explanation for that? >I wouldn't call that strange behaviour; I'd call that correct. ---JRG> I really appreciate your input, > > Monica > > > _________________________________________________________________ > [[trailing spam removed]] > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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.John R. Gleason Associate Professor Syracuse University 430 Huntington Hall Voice: 315-443-3107 Syracuse, NY 13244-2340 USA FAX: 315-443-4085 PGP public key at keyservers