[R] different results by re-ordering vector: bug?

Thomas Lumley tlumley at u.washington.edu
Sat Dec 27 18:19:14 CET 2003


On Fri, 26 Dec 2003, Carlos Soares wrote:

> The values for indices 10 and 3 of mean.row, which correspond to 6 and 8
> in the previous calculations, are not the same anymore:
>  > mean.row[10]==mean.row[3]
> [1] FALSE
>
> I understand that limited precision causes "incorrect" results but I
> wouldn't expect ordering operations to do the same. I couldn't find any
> information in the site about this. Maybe it's a bug with my version:

Almost certainly not.

The first thing to do is to see how big the difference is, rather than
comparing for equality.
mean.row[10]-mean.row[3].

You will find that it's about the same size as .Machine$double.eps, in
which case you just have an example of the fact that two floating point
numbers computed from different expressions are not reliably equal.
There's nothing puzzling about the fact that you just reordered the
numbers; floating point addition is not associative.


	-thomas




More information about the R-help mailing list