Ahh, I had no idea of this difference in rouding rules. I double checked my colleagues laptop and it indeed agrees with my laptop.
Thanks, Per On Fri, Apr 11, 2014 at 11:04 AM, peter dalgaard <[email protected]> wrote: > Google for "round to even", and read the Details section of ?round. > > > On 11 Apr 2014, at 10:42 , Per Nielsen <[email protected]> wrote: > > > Hi all > > > > I have encountered some strange/wrong behavior of the round function in > R. > > > > This is the behavior on my mac laptop: > > > >> R.version > > _ > > platform x86_64-apple-darwin13.0.2 > > arch x86_64 > > os darwin13.0.2 > > system x86_64, darwin13.0.2 > > status > > major 3 > > minor 0.2 > > year 2013 > > month 09 > > day 25 > > svn rev 63987 > > language R > > version.string R version 3.0.2 (2013-09-25) > > nickname Frisbee Sailing > >> round(1.5) > > [1] 2 > >> round(4.5) > > [1] 4 > >> floor(1.5 + 0.5) > > [1] 2 > >> floor(4.5 + 0.5) > > [1] 5 > > > > This is the behavior on Ubuntu 12.04 running in a virtual machine on the > > same mac: > > > >> R.version > > _ > > platform x86_64-pc-linux-gnu > > arch x86_64 > > os linux-gnu > > system x86_64, linux-gnu > > status beta > > major 3 > > minor 1.0 > > year 2014 > > month 03 > > day 28 > > svn rev 65330 > > language R > > version.string R version 3.1.0 beta (2014-03-28 r65330) > > nickname Spring Dance > >> round(1.5) > > [1] 2 > >> round(4.5) > > [1] 4 > >> floor(1.5 + 0.5) > > [1] 2 > >> floor(4.5 + 0.5) > > [1] 5 > > > > I would expect round(x.5) = x+1, which only happens sometimes. My > colleague > > using R version 3.1.0 on Linux on a Lenovo laptop gets the expected > result > > in all cases. > > > > Is this a bug or somehow expected behavior? It seems to be related to the > > mac hardware. I can ad hoc fix it using floor, but that is hardly > optimal. > > > > Thanks, > > Per > > > > [[alternative HTML version deleted]] > > > > _______________________________________________ > > R-SIG-Mac mailing list > > [email protected] > > https://stat.ethz.ch/mailman/listinfo/r-sig-mac > > -- > Peter Dalgaard, Professor > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Email: [email protected] Priv: [email protected] > > > [[alternative HTML version deleted]] _______________________________________________ R-SIG-Mac mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-mac
