[R] Loss of precision in read.csv.
Joshua Wiley
jwiley.psych at gmail.com
Sun Oct 10 07:43:04 CEST 2010
On Sat, Oct 9, 2010 at 2:38 PM, Joshua Wiley <jwiley.psych at gmail.com> wrote:
> Hi Steven,
>
> As near as I can tell, no precision is lost. R is just being
> courteous and not excessively filling our consoles. Try:
>
> print(airports[1,"latitude_deg"], digits = 22)
>
> which is the most digits R will print (although internally it can
> store more I believe).
Dr. Heiberger was kind enough to point out to that the maximum is 53
binary digits, as stated in the R FAQ 7.31:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
Slides by the same from the recent UseR! 2010 conference also provide
further explanation:
http://user2010.org/slides/Heiberger.pdf
One library that allows further precision is Rmpfr based on:
http://www.mpfr.org/
To give a small example borrowing the sprintf() display from Dr.
Heiberger's slides:
> library(Rmpfr)
> sprintf("%+17.17f", 2/3)
[1] "+0.66666666666666663"
> mpfr(2, 260)/3
1 'mpfr' number of precision 260 bits
[1] 0.66666666666666666666666666666666666666666666666666666666666666666666666666666685
>
My sincerest apologies for the previous misinformation.
Josh
<snip>
More information about the R-help
mailing list