Unexpected output from round()
On 12/06/2015 8:53 PM, John Maindonald wrote:
I cannot reproduce it (R version 3.2.0 Patched (2015-04-19 r68206)) in a terminal window:
If you set options(digits=16) you'll get it. It's just FAQ 7.31, and the fact that R only stores 15 or 16 digit accuracy. Duncan Murdoch
dput(pi)
3.14159265358979
round(dput(pi),2)
3.14159265358979 [1] 3.14
Cl <- c(82.9888290534313, 100.544763749464) dput(Cl)
c(82.9888290534313, 100.544763749464)
round(dput(Cl),2)
c(82.9888290534313, 100.544763749464) [1] 82.99 100.54
sessionInfo()
R version 3.2.0 Patched (2015-04-19 r68206) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.10.3 (Yosemite) locale: [1] en_NZ.UTF-8/en_NZ.UTF-8/en_NZ.UTF-8/C/en_NZ.UTF-8/en_NZ.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base John Maindonald email: john.maindonald at anu.edu.au
On 13/06/2015, at 12:39, Dennis Fisher <fisher at plessthan.com> wrote: R 3.2.0 OS X Colleagues I received unexpected output from a command issued in a terminal window:
dput(CI)
c(82.9888290534313, 100.544763749464)
round(dput(CI), 2)
c(82.9888290534313, 100.544763749464) [1] 82.98999999999999 100.54000000000001 I expected the result of the second command to be: 82.99 100.54 Interesting, the problem also occurs if I round to 5 or 8 digits. Of note, the problem does NOT occur in R GUI or in Windows. I am aware of FAQ 7.31 (Why doesn?t R think these numbers are equal?) but I don?t see how this could be manifestation of that issue. I am curious as to the explanation of this issue. Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com
_______________________________________________ R-SIG-Mac mailing list R-SIG-Mac at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-mac
_______________________________________________ R-SIG-Mac mailing list R-SIG-Mac at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-mac