![R seq function produces wrong results [closed]](https://www.xszz.org/skin/wt/rpic/t22.jpg)
Question:
It seems that one of my machines produces wrong results for seq function while another machine or the online r-fiddle (<a href="http://www.r-fiddle.org" rel="nofollow">http://www.r-fiddle.org</a>) interpreter give expected results. On the machine in question following happens:
seq(from = 1, to = 1.1, by = 0.01)
[1] 1.0 1.0 1.0 1.0 1.0 1.0 1.1 1.1 1.1 1.1 1.1
Changing the command slightly returns expected result
seq(from = 0.99, to = 1.1, by = 0.01)
[1] 0.99 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10
As soon as I cross the "1" threshold, the wrong result occurs, e.g. same when I do from = 2.95 to = 3.1, etc. Not sure how to find an answer as I couldn't replicate the problem on my other machine or on r-fiddle. The problem persists even after restarting the pc.
R version 3.1.3 (2015-03-09)<br /> Platform: x86_64-w64-mingw32/x64 (64-bit)<br /> Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:<br /> [1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252<br /> [3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C<br /> [5] LC_TIME=German_Germany.1252
Answer1:You have set the digits
option too low:
options(digits=2)
seq(from = 1, to = 1.1, by = 0.01)
#[1] 1.0 1.0 1.0 1.0 1.0 1.1 1.1 1.1 1.1 1.1 1.1
options(digits=7)
seq(from = 1, to = 1.1, by = 0.01)
#[1] 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10