[R] sensitivity logical operators in R
Nordlund, Dan (DSHS/RDA)
NordlDJ at dshs.wa.gov
Mon Jan 24 21:05:18 CET 2011
You have been given the answer already and a solution. See the R FAQ 7.31. As you have discovered this issue is not specific to R. In order to eliminate this "problem" entirely, you will need a computer system with infinite precision.
Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Marc Jekel
> Sent: Monday, January 24, 2011 11:48 AM
> Cc: r-help at r-project.org
> Subject: Re: [R] sensitivity logical operators in R
> Hi again,
> I have checked the same code (see below) using MATLAB. It produces the
> same error (i.e., equal numbers are evaluated as unequal). Do I miss
> Thanks for help!
> Marc Jekel schrieb:
> > Hello R Fans,
> > Another question for the community that really frightened me today.
> > The following logical comparison produces a "false" as output:
> > t = sum((c(.7,.69,.68,.67,.66)-.5)*c(1,1,-1,-1,1))
> > tt = sum((c(.7,.69,.68,.67,.66)-.5)*c(1,-1,1,1,-1))
> > t == tt
> > This is really strange behavior. Most likely this has something to do
> > how R represents numbers internally and the possible sensitivity of a
> > computer? Does anyone know when this strange behavior occurs and how
> > to fix it?
> > Thank you all! This list is pleasure!!!
> > Marc
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help