[R] equality of values

Oliver Ruebenacker curoli at gmail.com
Sun Jun 24 23:53:03 CEST 2012


     Hello,

  The FAQ answer 7.31 may be confusing to noobs and the referenced
paper is long. The essence is:

  (1) It's not an R issue, it is a floating point (flop) arithmetic issue.
  (2) The issue is that flop arithmetic is almost always only approximate.
  (3) Therefore, asking for exact equality of two flops is almost
always a mistake.
  (4) In simple cases, you can take the difference of two flops and
ask whether it is good enough
  (5) For extended calculations, you need to keep in mind that errors
propagate and accumulate.
  (6) Some ill-defined problems may lead to "solutions" that aren't
solutions (e.g. trying to invert a singular matrix)
  (7) Some well-defined problems may defy a straight-forward approach
(e.g. solving stiff differential equations)

     Take care
     Oliver

On Sun, Jun 24, 2012 at 5:29 PM, Sarah Goslee <sarah.goslee at gmail.com> wrote:
> Please read R FAQ 7.31, Why doesn't R think these numbers are equal?
>
> Sarah
>
> On Sun, Jun 24, 2012 at 1:58 PM, Andreia Leite
> <andreiaheitorleite at gmail.com> wrote:
>> Dear list,
>>
>> I'm trying to do a loop where I should choose a cell of a data frame
>> comparing it with another. The code actually works for the majority of the
>> loop but for some reason it doesn't and I can't figure out why.
>>
>> When I tried to understand why I've noticed this:
>>
>>> dif[11]
>> [1] 118.8333
>>> linhasUpdate[10,6]
>> [1] 118.8333
>>> dif[11]==linhasUpdate[10,6]
>> [1] FALSE
>>
>> Even though the values are the same R says they aren't! This happens for
>> some of the values (44) and for the others (128) it works fine.
>>
>> Does anybody why is this happening or a way to fix it? I' using 2.15.0.
>>
>> Thanks a lot!
>>
>> Andreia Leite
>>
>> --
> --
> Sarah Goslee
> http://www.functionaldiversity.org
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Oliver Ruebenacker, Bioinformatics and Network Analysis Consultant
President and Founder of Knowomics
(http://www.knowomics.com/wiki/Oliver_Ruebenacker)
Consultant at Predictive Medicine
(http://predmed.com/people/oliverruebenacker.html)
SBPAX: Turning Bio Knowledge into Math Models (http://www.sbpax.org)



More information about the R-help mailing list