[R] Numbers that look equal, should be equal, but if() doesn't see as equal (repost with code included)
Paul Lemmens
P.Lemmens at nici.kun.nl
Wed May 28 16:35:59 CEST 2003
Hoi Thomas,
--On woensdag 28 mei 2003 7:16 -0700 Thomas Lumley
<tlumley at u.washington.edu> wrote:
> On Wed, 28 May 2003, Paul Lemmens wrote:
>
>> Hi!
>>
>> Apologies for sending the mail without any code. Apparently somewhere
>> along the way the .R attachments got filtered out. I have included the
>> code below as clean as possible. My original mail is below the code.
>
> I still think you need not to be using ==. You want something like
>
> if ( abs(mean.b-mean.orig)/(epsilon+abs(mean.orig) < epsilon){
>
> You are effectively using epsilon=0, but epsilon=10e-10 should be
> adequate.
>
Based on all the hints and explanations I've changed the test to
'identical(all.equal(mean.b, mean.orig, tolerance=.Machine$double.eps),
FALSE)'.
I still need to look into the concept of finite precision, because I still
don't grasp how sometimes (as an extreme example, probably) 0.25 != 1/4.
That this will happen for a number with a lot of different decimals I can
understand (by an accumulation of rounding errors).
thnx all 4 your help!
--
Paul Lemmens
NICI, University of Nijmegen ASCII Ribbon Campaign /"\
Montessorilaan 3 (B.01.03) Against HTML Mail \ /
NL-6525 HR Nijmegen X
The Netherlands / \
Phonenumber +31-24-3612648
Fax +31-24-3616066
More information about the R-help
mailing list