[R] 0.3 is not 0.3, bug in seq() function?
Dear List, I've been running a numerical simulation and I found this odd error in my code where the which command could not identify which rows of a column of data.frame were corresponding to the value 0.3. There are 7 unique values in this column (0.01,0.05,0.1,0.2,0.3,0.4,0.5), and this does not work only for 0.3. So I looked at the column and manually tried to use the which() command, and the results were all FALSE despite I could see those number. So I recreated my sequence of number and tested: seq(0.1,0.5,0.1)[3]==0.3 which gave me FALSE!!! All the other numbers (0.1,0.2,0.4,0.5) give me TRUE, but 0.3 was not working. So I did: seq(0.1,0.5,0.1)[3]-0.3 which gave me 5.551115e-17. If you run a similar sequence like: seq(0.2,0.6,0.1)[2]==0.3 this will still give me FALSE. No, for my own purpose, I fixed the problem in this way: zerothree=seq(0.1,0.5,0.1)[3] which(data[,1]==zerothree) but I guess this bug is a bit of problem...Apologies if it is the wrong place to post this bug, and apologies also if this was a known issue. My version of R is : platform x86_64-pc-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 10.1 year 2009 month 12 day14 svn rev50720 language R version.string R version 2.10.1 (2009-12-14) Many Thanks, Enrico __ R-help@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.
Re: [R] 0.3 is not 0.3, bug in seq() function?
Enrico, The same happens with other numbers/sequences. seq(0.1,0.9,0.1)[7]==0.7 [1] FALSE seq(0.1,1.3,0.1)[12]==1.2 [1] FALSE Rounding seems to fix it, round(seq(0.1,0.5,0.1),1)[3]==0.3 round(seq(0.1,0.9,0.1),1)[7]==0.7 round(seq(0.1,1.3,0.1),1)[12]==1.2 They all return TRUE. Dr. Rubén Roa-Ureta AZTI - Tecnalia / Marine Research Unit Txatxarramendi Ugartea z/g 48395 Sukarrieta (Bizkaia) SPAIN -Mensaje original- De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] En nombre de Enrico R. Crema Enviado el: jueves, 28 de octubre de 2010 12:24 Para: r-help@r-project.org Asunto: [R] 0.3 is not 0.3, bug in seq() function? Dear List, I've been running a numerical simulation and I found this odd error in my code where the which command could not identify which rows of a column of data.frame were corresponding to the value 0.3. There are 7 unique values in this column (0.01,0.05,0.1,0.2,0.3,0.4,0.5), and this does not work only for 0.3. So I looked at the column and manually tried to use the which() command, and the results were all FALSE despite I could see those number. So I recreated my sequence of number and tested: seq(0.1,0.5,0.1)[3]==0.3 which gave me FALSE!!! All the other numbers (0.1,0.2,0.4,0.5) give me TRUE, but 0.3 was not working. So I did: seq(0.1,0.5,0.1)[3]-0.3 which gave me 5.551115e-17. If you run a similar sequence like: seq(0.2,0.6,0.1)[2]==0.3 this will still give me FALSE. No, for my own purpose, I fixed the problem in this way: zerothree=seq(0.1,0.5,0.1)[3] which(data[,1]==zerothree) but I guess this bug is a bit of problem...Apologies if it is the wrong place to post this bug, and apologies also if this was a known issue. My version of R is : platform x86_64-pc-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 10.1 year 2009 month 12 day14 svn rev50720 language R version.string R version 2.10.1 (2009-12-14) Many Thanks, Enrico __ R-help@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. __ R-help@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.
Re: [R] 0.3 is not 0.3, bug in seq() function?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 28/10/10 12:23, Enrico R. Crema wrote: Dear List, I've been running a numerical simulation and I found this odd error in my code where the which command could not identify which rows of a column of data.frame were corresponding to the value 0.3. There are 7 unique values in this column (0.01,0.05,0.1,0.2,0.3,0.4,0.5), and this does not work only for 0.3. So I looked at the column and manually tried to use the which() command, and the results were all FALSE despite I could see those number. So I recreated my sequence of number and tested: seq(0.1,0.5,0.1)[3]==0.3 which gave me FALSE!!! All the other numbers (0.1,0.2,0.4,0.5) give me TRUE, but 0.3 was not working. So I did: seq(0.1,0.5,0.1)[3]-0.3 which gave me 5.551115e-17. If you run a similar sequence like: seq(0.2,0.6,0.1)[2]==0.3 this will still give me FALSE. No, for my own purpose, I fixed the problem in this way: zerothree=seq(0.1,0.5,0.1)[3] which(data[,1]==zerothree) but I guess this bug is a bit of problem...Apologies if it is the wrong place to post this bug, and apologies also if this was a known issue. My version of R is : platform x86_64-pc-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 10.1 year 2009 month 12 day14 svn rev50720 language R version.string R version 2.10.1 (2009-12-14) This is not a bug, but based on the internal representation of numbers in the binary format. Numbers like 0.3 can not be represented as exactly 0.3, wherefore errors accumulate in a sequence. I can't provide you a link for more details, but the topic comes up every now and then in this mailing list. Cheers, Rainer Many Thanks, Enrico __ R-help@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. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel:+33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkzJVOEACgkQoYgNqgF2egpVXACeNO9GyRh9XKLg1g4EhcFs4Qa5 WXgAmgOdNB/xgmRS4UsMaEtunxS6NB/u =azme -END PGP SIGNATURE- __ R-help@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.
Re: [R] 0.3 is not 0.3, bug in seq() function?
Well...thanks to everybody for suggestions and reading...I guess I have to study more! Enrico On 28 Oct 2010, at 11:48, Rainer M Krug wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 28/10/10 12:23, Enrico R. Crema wrote: Dear List, I've been running a numerical simulation and I found this odd error in my code where the which command could not identify which rows of a column of data.frame were corresponding to the value 0.3. There are 7 unique values in this column (0.01,0.05,0.1,0.2,0.3,0.4,0.5), and this does not work only for 0.3. So I looked at the column and manually tried to use the which() command, and the results were all FALSE despite I could see those number. So I recreated my sequence of number and tested: seq(0.1,0.5,0.1)[3]==0.3 which gave me FALSE!!! All the other numbers (0.1,0.2,0.4,0.5) give me TRUE, but 0.3 was not working. So I did: seq(0.1,0.5,0.1)[3]-0.3 which gave me 5.551115e-17. If you run a similar sequence like: seq(0.2,0.6,0.1)[2]==0.3 this will still give me FALSE. No, for my own purpose, I fixed the problem in this way: zerothree=seq(0.1,0.5,0.1)[3] which(data[,1]==zerothree) but I guess this bug is a bit of problem...Apologies if it is the wrong place to post this bug, and apologies also if this was a known issue. My version of R is : platform x86_64-pc-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 10.1 year 2009 month 12 day14 svn rev50720 language R version.string R version 2.10.1 (2009-12-14) This is not a bug, but based on the internal representation of numbers in the binary format. Numbers like 0.3 can not be represented as exactly 0.3, wherefore errors accumulate in a sequence. I can't provide you a link for more details, but the topic comes up every now and then in this mailing list. Cheers, Rainer Many Thanks, Enrico __ R-help@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. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel:+33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkzJVOEACgkQoYgNqgF2egpVXACeNO9GyRh9XKLg1g4EhcFs4Qa5 WXgAmgOdNB/xgmRS4UsMaEtunxS6NB/u =azme -END PGP SIGNATURE- __ R-help@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.
Re: [R] 0.3 is not 0.3, bug in seq() function?
Enrico R. Crema enryu_cr...@yahoo.it 28/10/2010 12:08:55 Well...thanks to everybody for suggestions and reading...I guess I have to study more! ... On 28/10/10 12:23, Enrico R. Crema wrote: I can't provide you a link for more details, The canonical link is R FAQ 7.31 in the 'Frequently Asked Questions' issued as part of the R HTML Help system. Steve E *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@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.
Re: [R] 0.3 is not 0.3, bug in seq() function?
Hi, It is a know issue, reported in the FAQ 7.31. Ivan Le 10/28/2010 13:08, Enrico R. Crema a écrit : Well...thanks to everybody for suggestions and reading...I guess I have to study more! Enrico On 28 Oct 2010, at 11:48, Rainer M Krug wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 28/10/10 12:23, Enrico R. Crema wrote: Dear List, I've been running a numerical simulation and I found this odd error in my code where the which command could not identify which rows of a column of data.frame were corresponding to the value 0.3. There are 7 unique values in this column (0.01,0.05,0.1,0.2,0.3,0.4,0.5), and this does not work only for 0.3. So I looked at the column and manually tried to use the which() command, and the results were all FALSE despite I could see those number. So I recreated my sequence of number and tested: seq(0.1,0.5,0.1)[3]==0.3 which gave me FALSE!!! All the other numbers (0.1,0.2,0.4,0.5) give me TRUE, but 0.3 was not working. So I did: seq(0.1,0.5,0.1)[3]-0.3 which gave me 5.551115e-17. If you run a similar sequence like: seq(0.2,0.6,0.1)[2]==0.3 this will still give me FALSE. No, for my own purpose, I fixed the problem in this way: zerothree=seq(0.1,0.5,0.1)[3] which(data[,1]==zerothree) but I guess this bug is a bit of problem...Apologies if it is the wrong place to post this bug, and apologies also if this was a known issue. My version of R is : platform x86_64-pc-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 10.1 year 2009 month 12 day14 svn rev50720 language R version.string R version 2.10.1 (2009-12-14) This is not a bug, but based on the internal representation of numbers in the binary format. Numbers like 0.3 can not be represented as exactly 0.3, wherefore errors accumulate in a sequence. I can't provide you a link for more details, but the topic comes up every now and then in this mailing list. Cheers, Rainer Many Thanks, Enrico __ R-help@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. - -- Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany) Centre of Excellence for Invasion Biology Natural Sciences Building Office Suite 2039 Stellenbosch University Main Campus, Merriman Avenue Stellenbosch South Africa Tel:+33 - (0)9 53 10 27 44 Cell: +27 - (0)8 39 47 90 42 Fax (SA): +27 - (0)8 65 16 27 82 Fax (D) : +49 - (0)3 21 21 25 22 44 Fax (FR): +33 - (0)9 58 10 27 44 email: rai...@krugs.de Skype: RMkrug -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkzJVOEACgkQoYgNqgF2egpVXACeNO9GyRh9XKLg1g4EhcFs4Qa5 WXgAmgOdNB/xgmRS4UsMaEtunxS6NB/u =azme -END PGP SIGNATURE- __ R-help@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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php __ R-help@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.