[R] scan seems to modify the data
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Mar 31 20:34:21 CEST 2004
On 31 Mar 2004, Peter Dalgaard wrote:
> Duncan Murdoch <dmurdoch at pair.com> writes:
>
> > > print(x,17)
> > [1] 0.26600000000000001 0.25100000000000000
> ...
> > > print(x,17)
> > [1] 0.266
> >
> > I don't know why the second print() prints 0.266 differently from the
> > first one. (This is in the 1.9.0 beta in Windows).
>
> To get the same number of decimals as the other guy. The interesting
> question is why 0.251 gets all those trailing zeros:
>
> > print(0.251,17)
> [1] 0.25100000000000000
> > print(0.253,17)
> [1] 0.25300000000000000
> > print(0.255,17)
> [1] 0.255
Take a look at formatReal. scientific thinks 0.251 has 17 digits and
0.255 has 3. It really doesn't make any sense to ask for more precision
than you have (.Machine$double.eps) and you do often get spurious
errors if you attempt to do so. So 15 digits is normally safe, but no
more.
Note that there are decimal -> binary -> decimal conversions and you
can't say which one introduced the small changes.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list