Unknown anomaly

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unknown anomaly

Benjamin Robira
Dear Sir,

I writting to you as I am facing an irregularity in R that I do not know
the origin. When doing a sequence from 0 to 1 by 0.02 and assigning it to
a vector (i.e. code: a <- seq(from=0, to=1, by=0.02)) then, when I try to
use the 36th element (and two others behave the same way) it is not
recognized correctly. For instance a[36]==0.7, what should give TRUE,
gives instead FALSE. However, this works fine for element 35 and 37 and
all other elements but two.
I do not know the reason. I restarted my R session and tried on another
computer. This has been the same. None of my colleagues had an answer. I
hope that you would be able to help me fix that as it must be a pretty
straightforward error that I do not realise.

I would be thankful for any help,
With my very Best Regards,
Benjamin.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unknown anomaly

Boris Steipe
The concept of equality for numbers that are represented on a computer is frequently misapplied. Consider:

a <- seq(from=0, to=1, by=0.02)

print(a[36])
[1] 0.7

a[36] == 0.7
[1] FALSE

print(a[36], digits=22)
[1] 0.7000000000000000666134

a[36] == 0.7000000000000001
[1] TRUE

All clear?


B.



> On Apr 18, 2017, at 9:55 PM, Benjamin Robira <[hidden email]> wrote:
>
> Dear Sir,
>
> I writting to you as I am facing an irregularity in R that I do not know
> the origin. When doing a sequence from 0 to 1 by 0.02 and assigning it to
> a vector (i.e. code: a <- seq(from=0, to=1, by=0.02)) then, when I try to
> use the 36th element (and two others behave the same way) it is not
> recognized correctly. For instance a[36]==0.7, what should give TRUE,
> gives instead FALSE. However, this works fine for element 35 and 37 and
> all other elements but two.
> I do not know the reason. I restarted my R session and tried on another
> computer. This has been the same. None of my colleagues had an answer. I
> hope that you would be able to help me fix that as it must be a pretty
> straightforward error that I do not realise.
>
> I would be thankful for any help,
> With my very Best Regards,
> Benjamin.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unknown anomaly

Richard M. Heiberger
In reply to this post by Benjamin Robira
This is the standard behavior of floating point arithmetic on a
digital computer.  Computers use 53-bit finite precision arithmetic.
They do not use infinite precision real numbers. Please see FAQ 7.31
for details.

The FAQ is in the R documentation on your computer in file
   system.file("../../doc/FAQ")
Locate the file from the R prompt and then open in your favorite text editor.


On Tue, Apr 18, 2017 at 9:55 PM, Benjamin Robira <[hidden email]> wrote:

> Dear Sir,
>
> I writting to you as I am facing an irregularity in R that I do not know
> the origin. When doing a sequence from 0 to 1 by 0.02 and assigning it to
> a vector (i.e. code: a <- seq(from=0, to=1, by=0.02)) then, when I try to
> use the 36th element (and two others behave the same way) it is not
> recognized correctly. For instance a[36]==0.7, what should give TRUE,
> gives instead FALSE. However, this works fine for element 35 and 37 and
> all other elements but two.
> I do not know the reason. I restarted my R session and tried on another
> computer. This has been the same. None of my colleagues had an answer. I
> hope that you would be able to help me fix that as it must be a pretty
> straightforward error that I do not realise.
>
> I would be thankful for any help,
> With my very Best Regards,
> Benjamin.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unknown anomaly

Bert Gunter-2
In reply to this post by Boris Steipe
FAQ 7.31.

-- Bert

(The FAQ's exist for a reason. You should read them!)

Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Tue, Apr 18, 2017 at 7:53 PM, Boris Steipe <[hidden email]> wrote:

> The concept of equality for numbers that are represented on a computer is frequently misapplied. Consider:
>
> a <- seq(from=0, to=1, by=0.02)
>
> print(a[36])
> [1] 0.7
>
> a[36] == 0.7
> [1] FALSE
>
> print(a[36], digits=22)
> [1] 0.7000000000000000666134
>
> a[36] == 0.7000000000000001
> [1] TRUE
>
> All clear?
>
>
> B.
>
>
>
>> On Apr 18, 2017, at 9:55 PM, Benjamin Robira <[hidden email]> wrote:
>>
>> Dear Sir,
>>
>> I writting to you as I am facing an irregularity in R that I do not know
>> the origin. When doing a sequence from 0 to 1 by 0.02 and assigning it to
>> a vector (i.e. code: a <- seq(from=0, to=1, by=0.02)) then, when I try to
>> use the 36th element (and two others behave the same way) it is not
>> recognized correctly. For instance a[36]==0.7, what should give TRUE,
>> gives instead FALSE. However, this works fine for element 35 and 37 and
>> all other elements but two.
>> I do not know the reason. I restarted my R session and tried on another
>> computer. This has been the same. None of my colleagues had an answer. I
>> hope that you would be able to help me fix that as it must be a pretty
>> straightforward error that I do not realise.
>>
>> I would be thankful for any help,
>> With my very Best Regards,
>> Benjamin.
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unknown anomaly

Rolf Turner
In reply to this post by Benjamin Robira
On 19/04/17 13:55, Benjamin Robira wrote:

> Dear Sir,
>
> I writting to you as I am facing an irregularity in R that I do not know
> the origin. When doing a sequence from 0 to 1 by 0.02 and assigning it to
> a vector (i.e. code: a <- seq(from=0, to=1, by=0.02)) then, when I try to
> use the 36th element (and two others behave the same way) it is not
> recognized correctly. For instance a[36]==0.7, what should give TRUE,
> gives instead FALSE. However, this works fine for element 35 and 37 and
> all other elements but two.
> I do not know the reason. I restarted my R session and tried on another
> computer. This has been the same. None of my colleagues had an answer. I
> hope that you would be able to help me fix that as it must be a pretty
> straightforward error that I do not realise.
>
> I would be thankful for any help.


See FAQ 7.31.

cheers,

Rolf Turner

--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Loading...