# I can't get seq to behave how I think it should

 Classic List Threaded
10 messages
Reply | Threaded
Open this post in threaded view
|

 I am using seq with the expression seq(1.4, 2.1, by=0.001) to create a sequence of references from 1.4 to 2.1 in 0.001 increments.  They appear to be created correctly.  They have a related pair of data which for the purposes of this we will call val.  I'm interested in the content on the row with seq = 1.8. But I can't seem to get it returned.  I can get other values but not 1.8!  yet looking at row 401 there is nothing to indicate an issue > a = 1.4 > b = 2.1 > seq = seq(a, b, by=0.001) > val = ceiling(seq * 50) > s=data.frame(seq, val) > s$val[seq==1.799] [1] 90 > s$val[s$seq==1.8] numeric(0) > s$val[seq==1.8] numeric(0) > s$val[s$seq==1.800] numeric(0) > s$val[s$seq==1.801] [1] 91 > head(s[s$seq>1.798,]) seq val 400 1.799 90 401 1.800 90 402 1.801 91 403 1.802 91 404 1.803 91 405 1.804 91 Can anyone explain what's going on here and how I would correctly find the content of row 401 by using an expression to equal the seq column? ******************************************************************************************************************** This message may contain confidential information. If yo...{{dropped:19}} ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Reply | Threaded Open this post in threaded view | ## Re: I can't get seq to behave how I think it should  Hi, This looks like a floating point reality bump - see https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f You can use other methods to finding your row - I would opt for findInterval() > lut = seq(1.4, 2.1, by=0.001) > findInterval(1.8, lut) [1] 401 findInterval() uses a rapid search to find the index in the look up table (lut) that is just less than or equal to the search value (in your example 1.8). Cheers, Ben > On Jan 17, 2019, at 8:33 AM, POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST) via R-help <[hidden email]> wrote: > > I am using seq with the expression seq(1.4, 2.1, by=0.001) to create a sequence of references from 1.4 to 2.1 in 0.001 increments. They appear to be created correctly. They have a related pair of data which for the purposes of this we will call val. I'm interested in the content on the row with seq = 1.8. But I can't seem to get it returned. I can get other values but not 1.8! yet looking at row 401 there is nothing to indicate an issue > >> a = 1.4 >> b = 2.1 >> seq = seq(a, b, by=0.001) >> val = ceiling(seq * 50) >> s=data.frame(seq, val) >> s$val[seq==1.799] > [1] 90 >> s$val[s$seq==1.8] > numeric(0) >> s$val[seq==1.8] > numeric(0) >> s$val[s$seq==1.800] > numeric(0) >> s$val[s$seq==1.801] > [1] 91 >> head(s[s$seq>1.798,]) >      seq val > 400 1.799  90 > 401 1.800  90 > 402 1.801  91 > 403 1.802  91 > 404 1.803  91 > 405 1.804  91 > > > Can anyone explain what's going on here and how I would correctly find the content of row 401 by using an expression to equal the seq column? > > > > > > ******************************************************************************************************************** > > This message may contain confidential information. If ...{{dropped:25}} ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

 Hi Or you could use rounding. which(round(lut, 3)==1.8) [1] 401 Cheers Petr > -----Original Message----- > From: R-help <[hidden email]> On Behalf Of Ben Tupper > Sent: Thursday, January 17, 2019 2:43 PM > To: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS > FOUNDATION TRUST) <[hidden email]> > Cc: [hidden email] > Subject: Re: [R] I can't get seq to behave how I think it should > > Hi, > > This looks like a floating point reality bump - see > > https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-> these-numbers-are-equal_003f FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f> > > You can use other methods to finding your row - I would opt for findInterval() > > > lut = seq(1.4, 2.1, by=0.001) > > findInterval(1.8, lut) > [1] 401 > > findInterval() uses a rapid search to find the index in the look up table (lut) that > is just less than  or equal to the search value (in your example 1.8). > > Cheers, > Ben > > > On Jan 17, 2019, at 8:33 AM, POLWART, Calum (COUNTY DURHAM AND > DARLINGTON NHS FOUNDATION TRUST) via R-help <[hidden email]> > wrote: > > > > I am using seq with the expression seq(1.4, 2.1, by=0.001) to create a > > sequence of references from 1.4 to 2.1 in 0.001 increments.  They > > appear to be created correctly.  They have a related pair of data > > which for the purposes of this we will call val.  I'm interested in > > the content on the row with seq = 1.8. But I can't seem to get it > > returned.  I can get other values but not 1.8!  yet looking at row 401 > > there is nothing to indicate an issue > > > >> a = 1.4 > >> b = 2.1 > >> seq = seq(a, b, by=0.001) > >> val = ceiling(seq * 50) > >> s=data.frame(seq, val) > >> s$val[seq==1.799] > > [1] 90 > >> s$val[s$seq==1.8] > > numeric(0) > >> s$val[seq==1.8] > > numeric(0) > >> s$val[s$seq==1.800] > > numeric(0) > >> s$val[s$seq==1.801] > > [1] 91 > >> head(s[s$seq>1.798,]) > > seq val > > 400 1.799 90 > > 401 1.800 90 > > 402 1.801 91 > > 403 1.802 91 > > 404 1.803 91 > > 405 1.804 91 > > > > > > Can anyone explain what's going on here and how I would correctly find the > content of row 401 by using an expression to equal the seq column? > > > > > > > > > > > > > ******************************************************************* > *** > > ********************************************** > > > > This message may contain confidential information. If > > ...{{dropped:25}} > > ______________________________________________ > [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. Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Reply | Threaded Open this post in threaded view | ## Re: I can't get seq to behave how I think it should  Thanks guys. I've used Petr's method and its working for me. If the data had been from a calculation I'd have rounded it... just didn't expect seq to break it! C -----Original Message----- From: PIKAL Petr [mailto:[hidden email]] Sent: 17 January 2019 13:53 To: Ben Tupper; POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST) Cc: [hidden email] Subject: RE: [R] I can't get seq to behave how I think it should Hi Or you could use rounding. which(round(lut, 3)==1.8) [1] 401 Cheers Petr > -----Original Message----- > From: R-help <[hidden email]> On Behalf Of Ben Tupper > Sent: Thursday, January 17, 2019 2:43 PM > To: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST) > <[hidden email]> > Cc: [hidden email] > Subject: Re: [R] I can't get seq to behave how I think it should > > Hi, > > This looks like a floating point reality bump - see > > https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-> these-numbers-are-equal_003f FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f> > > You can use other methods to finding your row - I would opt for > findInterval() > > > lut = seq(1.4, 2.1, by=0.001) > > findInterval(1.8, lut) > [1] 401 > > findInterval() uses a rapid search to find the index in the look up > table (lut) that is just less than or equal to the search value (in your example 1.8). > > Cheers, > Ben > > > On Jan 17, 2019, at 8:33 AM, POLWART, Calum (COUNTY DURHAM AND > DARLINGTON NHS FOUNDATION TRUST) via R-help <[hidden email]> > wrote: > > > > I am using seq with the expression seq(1.4, 2.1, by=0.001) to create > > a sequence of references from 1.4 to 2.1 in 0.001 increments. They > > appear to be created correctly. They have a related pair of data > > which for the purposes of this we will call val. I'm interested in > > the content on the row with seq = 1.8. But I can't seem to get it > > returned. I can get other values but not 1.8! yet looking at row > > 401 there is nothing to indicate an issue > > > >> a = 1.4 > >> b = 2.1 > >> seq = seq(a, b, by=0.001) > >> val = ceiling(seq * 50) > >> s=data.frame(seq, val) > >> s$val[seq==1.799] > > [1] 90 > >> s$val[s$seq==1.8] > > numeric(0) > >> s$val[seq==1.8] > > numeric(0) > >> s$val[s$seq==1.800] > > numeric(0) > >> s$val[s$seq==1.801] > > [1] 91 > >> head(s[s$seq>1.798,]) > >      seq val > > 400 1.799  90 > > 401 1.800  90 > > 402 1.801  91 > > 403 1.802  91 > > 404 1.803  91 > > 405 1.804  91 > > > > > > Can anyone explain what's going on here and how I would correctly > > find the > content of row 401 by using an expression to equal the seq column? > > > > > > > > > > > > > ******************************************************************* > *** > > ********************************************** > > > > This message may contain confidential information. If > > ...{{dropped:25}} > > ______________________________________________ > [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. Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/******************************************************************************************************************** This message may contain confidential information. If you are not the intended recipient please inform the sender that you have received the message in error before deleting it. Please do not disclose, copy or distribute information in this e-mail or take any action in relation to its contents. To do so is strictly prohibited and may be unlawful. Thank you for your co-operation. NHSmail is the secure email and directory service available for all NHS staff in England and Scotland. NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and other accredited email services. For more information and to find out how you can switch, https://portal.nhs.net/help/joiningnhsmail______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

 Hi It is not seq problem, it is floating point numbers representation in finit precision problem. Ben pointed to it and you could learn about it from FAQ 7.31. Cheers Petr > -----Original Message----- > From: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS > FOUNDATION TRUST) <[hidden email]> > Sent: Thursday, January 17, 2019 2:56 PM > To: PIKAL Petr <[hidden email]>; Ben Tupper <[hidden email]> > Cc: [hidden email] > Subject: RE: [R] I can't get seq to behave how I think it should > > Thanks guys. > > I've used Petr's method and its working for me. > > If the data had been from a calculation I'd have rounded it... just didn't expect > seq to break it! > > C > > -----Original Message----- > From: PIKAL Petr [mailto:[hidden email]] > Sent: 17 January 2019 13:53 > To: Ben Tupper; POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS > FOUNDATION TRUST) > Cc: [hidden email] > Subject: RE: [R] I can't get seq to behave how I think it should > > Hi > > Or you could use rounding. > which(round(lut, 3)==1.8) > [1] 401 > > Cheers > Petr > > > -----Original Message----- > > From: R-help <[hidden email]> On Behalf Of Ben Tupper > > Sent: Thursday, January 17, 2019 2:43 PM > > To: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS > FOUNDATION TRUST) > > <[hidden email]> > > Cc: [hidden email] > > Subject: Re: [R] I can't get seq to behave how I think it should > > > > Hi, > > > > This looks like a floating point reality bump - see > > > > https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-> > these-numbers-are-equal_003f > FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f> > > > > You can use other methods to finding your row - I would opt for > > findInterval() > > > > > lut = seq(1.4, 2.1, by=0.001) > > > findInterval(1.8, lut) > > [1] 401 > > > > findInterval() uses a rapid search to find the index in the look up > > table (lut) that is just less than  or equal to the search value (in your example > 1.8). > > > > Cheers, > > Ben > > > > > On Jan 17, 2019, at 8:33 AM, POLWART, Calum (COUNTY DURHAM AND > > DARLINGTON NHS FOUNDATION TRUST) via R-help <[hidden email]> > > wrote: > > > > > > I am using seq with the expression seq(1.4, 2.1, by=0.001) to create > > > a sequence of references from 1.4 to 2.1 in 0.001 increments.  They > > > appear to be created correctly.  They have a related pair of data > > > which for the purposes of this we will call val.  I'm interested in > > > the content on the row with seq = 1.8. But I can't seem to get it > > > returned.  I can get other values but not 1.8!  yet looking at row > > > 401 there is nothing to indicate an issue > > > > > >> a = 1.4 > > >> b = 2.1 > > >> seq = seq(a, b, by=0.001) > > >> val = ceiling(seq * 50) > > >> s=data.frame(seq, val) > > >> s$val[seq==1.799] > > > [1] 90 > > >> s$val[s$seq==1.8] > > > numeric(0) > > >> s$val[seq==1.8] > > > numeric(0) > > >> s$val[s$seq==1.800] > > > numeric(0) > > >> s$val[s$seq==1.801] > > > [1] 91 > > >> head(s[s$seq>1.798,]) > > > seq val > > > 400 1.799 90 > > > 401 1.800 90 > > > 402 1.801 91 > > > 403 1.802 91 > > > 404 1.803 91 > > > 405 1.804 91 > > > > > > > > > Can anyone explain what's going on here and how I would correctly > > > find the > > content of row 401 by using an expression to equal the seq column? > > > > > > > > > > > > > > > > > > > > > ******************************************************************* > > *** > > > ********************************************** > > > > > > This message may contain confidential information. If > > > ...{{dropped:25}} > > > > ______________________________________________ > > [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. > Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních > partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-> ochrany-osobnich-udaju/ | Information about processing and protection of > business partner’s personal data are available on website: > https://www.precheza.cz/en/personal-data-protection-principles/> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné > a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: > https://www.precheza.cz/01-dovetek/ | This email and any documents > attached to it may be confidential and are subject to the legally binding > disclaimer: https://www.precheza.cz/en/01-disclaimer/> > > > ******************************************************************* > ************************************************* > > This message may contain confidential information. If you are not the intended > recipient please inform the sender that you have received the message in error > before deleting it. > Please do not disclose, copy or distribute information in this e-mail or take any > action in relation to its contents. To do so is strictly prohibited and may be > unlawful. Thank you for your co-operation. > > NHSmail is the secure email and directory service available for all NHS staff in > England and Scotland. NHSmail is approved for exchanging patient data and > other sensitive information with NHSmail and other accredited email services. > > For more information and to find out how you can switch, > https://portal.nhs.net/help/joiningnhsmailOsobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Reply | Threaded Open this post in threaded view | ## Re: I can't get seq to behave how I think it should  Well I get the issue with finite precision. As in SQRT(2) * SQRT(2) is not 2. What surprised me was that seq(1.4, 2.1, by=0.001) starts at 1.3999999999999999 and not 1.4! -----Original Message----- From: PIKAL Petr [mailto:[hidden email]] Sent: 17 January 2019 14:30 To: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST); Ben Tupper Cc: [hidden email] Subject: RE: [R] I can't get seq to behave how I think it should Hi It is not seq problem, it is floating point numbers representation in finit precision problem. Ben pointed to it and you could learn about it from FAQ 7.31. Cheers Petr > -----Original Message----- > From: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION > TRUST) <[hidden email]> > Sent: Thursday, January 17, 2019 2:56 PM > To: PIKAL Petr <[hidden email]>; Ben Tupper > <[hidden email]> > Cc: [hidden email] > Subject: RE: [R] I can't get seq to behave how I think it should > > Thanks guys. > > I've used Petr's method and its working for me. > > If the data had been from a calculation I'd have rounded it... just > didn't expect seq to break it! > > C > > -----Original Message----- > From: PIKAL Petr [mailto:[hidden email]] > Sent: 17 January 2019 13:53 > To: Ben Tupper; POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS > FOUNDATION TRUST) > Cc: [hidden email] > Subject: RE: [R] I can't get seq to behave how I think it should > > Hi > > Or you could use rounding. > which(round(lut, 3)==1.8) > [1] 401 > > Cheers > Petr > > > -----Original Message----- > > From: R-help <[hidden email]> On Behalf Of Ben Tupper > > Sent: Thursday, January 17, 2019 2:43 PM > > To: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS > FOUNDATION TRUST) > > <[hidden email]> > > Cc: [hidden email] > > Subject: Re: [R] I can't get seq to behave how I think it should > > > > Hi, > > > > This looks like a floating point reality bump - see > > > > https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-thin> > k- these-numbers-are-equal_003f > > > FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f> > > > > You can use other methods to finding your row - I would opt for > > findInterval() > > > > > lut = seq(1.4, 2.1, by=0.001) > > > findInterval(1.8, lut) > > [1] 401 > > > > findInterval() uses a rapid search to find the index in the look up > > table (lut) that is just less than or equal to the search value (in > > your example > 1.8). > > > > Cheers, > > Ben > > > > > On Jan 17, 2019, at 8:33 AM, POLWART, Calum (COUNTY DURHAM AND > > DARLINGTON NHS FOUNDATION TRUST) via R-help <[hidden email]> > > wrote: > > > > > > I am using seq with the expression seq(1.4, 2.1, by=0.001) to > > > create a sequence of references from 1.4 to 2.1 in 0.001 > > > increments. They appear to be created correctly. They have a > > > related pair of data which for the purposes of this we will call > > > val. I'm interested in the content on the row with seq = 1.8. But > > > I can't seem to get it returned. I can get other values but not > > > 1.8! yet looking at row > > > 401 there is nothing to indicate an issue > > > > > >> a = 1.4 > > >> b = 2.1 > > >> seq = seq(a, b, by=0.001) > > >> val = ceiling(seq * 50) > > >> s=data.frame(seq, val) > > >> s$val[seq==1.799] > > > [1] 90 > > >> s$val[s$seq==1.8] > > > numeric(0) > > >> s$val[seq==1.8] > > > numeric(0) > > >> s$val[s$seq==1.800] > > > numeric(0) > > >> s$val[s$seq==1.801] > > > [1] 91 > > >> head(s[s$seq>1.798,]) > > >      seq val > > > 400 1.799  90 > > > 401 1.800  90 > > > 402 1.801  91 > > > 403 1.802  91 > > > 404 1.803  91 > > > 405 1.804  91 > > > > > > > > > Can anyone explain what's going on here and how I would correctly > > > find the > > content of row 401 by using an expression to equal the seq column? > > > > > > > > > > > > > > > > > > > > > ******************************************************************* > > *** > > > ********************************************** > > > > > > This message may contain confidential information. If > > > ...{{dropped:25}} > > > > ______________________________________________ > > [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. > Osobní údaje: Informace o zpracování a ochraně osobních údajů > obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: > https://www.precheza.cz/zasady- ochrany-osobnich-udaju/ | Information > about processing and protection of business partner’s personal data are available on website: > https://www.precheza.cz/en/personal-data-protection-principles/> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou > důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: > https://www.precheza.cz/01-dovetek/ | This email and any documents > attached to it may be confidential and are subject to the legally > binding > disclaimer: https://www.precheza.cz/en/01-disclaimer/> > > > ******************************************************************* > ************************************************* > > This message may contain confidential information. If you are not the > intended recipient please inform the sender that you have received the > message in error before deleting it. > Please do not disclose, copy or distribute information in this e-mail > or take any action in relation to its contents. To do so is strictly > prohibited and may be unlawful. Thank you for your co-operation. > > NHSmail is the secure email and directory service available for all > NHS staff in England and Scotland. NHSmail is approved for exchanging > patient data and other sensitive information with NHSmail and other accredited email services. > > For more information and to find out how you can switch, > https://portal.nhs.net/help/joiningnhsmailOsobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/******************************************************************************************************************** This message may contain confidential information. If you are not the intended recipient please inform the sender that you have received the message in error before deleting it. Please do not disclose, copy or distribute information in this e-mail or take any action in relation to its contents. To do so is strictly prohibited and may be unlawful. Thank you for your co-operation. NHSmail is the secure email and directory service available for all NHS staff in England and Scotland. NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and other accredited email services. For more information and to find out how you can switch, https://portal.nhs.net/help/joiningnhsmail______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

 ... then you still don't understand. Perhaps you might find [1] helpful. Also, adding a floating point representation of 0.001 to 1.4 for 400 times does not yield the same approximation of 1.8 that you get by directly converting the string "1.8" that you typed into your R interpreter. [1] https://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/On January 17, 2019 6:56:48 AM PST, "POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST) via R-help" <[hidden email]> wrote: >Well I get the issue with finite precision. As in SQRT(2) * SQRT(2) is >not 2. > >What surprised me was that seq(1.4, 2.1, by=0.001) starts at >1.3999999999999999 and not 1.4! > > >-----Original Message----- >From: PIKAL Petr [mailto:[hidden email]] >Sent: 17 January 2019 14:30 >To: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST); >Ben Tupper >Cc: [hidden email] >Subject: RE: [R] I can't get seq to behave how I think it should > >Hi > >It is not seq problem, it is floating point numbers representation in >finit precision problem. Ben pointed to it and you could learn about it >from FAQ 7.31. > >Cheers >Petr > >> -----Original Message----- >> From: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION >> TRUST) <[hidden email]> >> Sent: Thursday, January 17, 2019 2:56 PM >> To: PIKAL Petr <[hidden email]>; Ben Tupper >> <[hidden email]> >> Cc: [hidden email] >> Subject: RE: [R] I can't get seq to behave how I think it should >> >> Thanks guys. >> >> I've used Petr's method and its working for me. >> >> If the data had been from a calculation I'd have rounded it... just >> didn't expect seq to break it! >> >> C >> >> -----Original Message----- >> From: PIKAL Petr [mailto:[hidden email]] >> Sent: 17 January 2019 13:53 >> To: Ben Tupper; POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS >> FOUNDATION TRUST) >> Cc: [hidden email] >> Subject: RE: [R] I can't get seq to behave how I think it should >> >> Hi >> >> Or you could use rounding. >> which(round(lut, 3)==1.8) >> [1] 401 >> >> Cheers >> Petr >> >> > -----Original Message----- >> > From: R-help <[hidden email]> On Behalf Of Ben Tupper >> > Sent: Thursday, January 17, 2019 2:43 PM >> > To: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS >> FOUNDATION TRUST) >> > <[hidden email]> >> > Cc: [hidden email] >> > Subject: Re: [R] I can't get seq to behave how I think it should >> > >> > Hi, >> > >> > This looks like a floating point reality bump - see >> > >> > >https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-thin>> > k- these-numbers-are-equal_003f >> > > > FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f> >> > >> > You can use other methods to finding your row - I would opt for >> > findInterval() >> > >> > > lut = seq(1.4, 2.1, by=0.001) >> > > findInterval(1.8, lut) >> > [1] 401 >> > >> > findInterval() uses a rapid search to find the index in the look up >> > table (lut) that is just less than  or equal to the search value >(in >> > your example >> 1.8). >> > >> > Cheers, >> > Ben >> > >> > > On Jan 17, 2019, at 8:33 AM, POLWART, Calum (COUNTY DURHAM AND >> > DARLINGTON NHS FOUNDATION TRUST) via R-help <[hidden email]> >> > wrote: >> > > >> > > I am using seq with the expression seq(1.4, 2.1, by=0.001) to >> > > create a sequence of references from 1.4 to 2.1 in 0.001 >> > > increments.  They appear to be created correctly.  They have a >> > > related pair of data which for the purposes of this we will call >> > > val.  I'm interested in the content on the row with seq = 1.8. >But >> > > I can't seem to get it returned.  I can get other values but not >> > > 1.8!  yet looking at row >> > > 401 there is nothing to indicate an issue >> > > >> > >> a = 1.4 >> > >> b = 2.1 >> > >> seq = seq(a, b, by=0.001) >> > >> val = ceiling(seq * 50) >> > >> s=data.frame(seq, val) >> > >> s$val[seq==1.799] >> > > [1] 90 >> > >> s$val[s$seq==1.8] >> > > numeric(0) >> > >> s$val[seq==1.8] >> > > numeric(0) >> > >> s$val[s$seq==1.800] >> > > numeric(0) >> > >> s$val[s$seq==1.801] >> > > [1] 91 >> > >> head(s[s$seq>1.798,]) >> > > seq val >> > > 400 1.799 90 >> > > 401 1.800 90 >> > > 402 1.801 91 >> > > 403 1.802 91 >> > > 404 1.803 91 >> > > 405 1.804 91 >> > > >> > > >> > > Can anyone explain what's going on here and how I would correctly >> > > find the >> > content of row 401 by using an expression to equal the seq column? >> > > >> > > >> > > >> > > >> > > >> > > >> > >> ******************************************************************* >> > *** >> > > ********************************************** >> > > >> > > This message may contain confidential information. If >> > > ...{{dropped:25}} >> > >> > ______________________________________________ >> > [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. >> Osobní údaje: Informace o zpracování a ochraně osobních údajů >> obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: >> https://www.precheza.cz/zasady- ochrany-osobnich-udaju/ | Information >> about processing and protection of business partner’s personal data >are available on website: >> https://www.precheza.cz/en/personal-data-protection-principles/>> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou >> důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení >odpovědnosti: >> https://www.precheza.cz/01-dovetek/ | This email and any documents >> attached to it may be confidential and are subject to the legally >> binding >> disclaimer: https://www.precheza.cz/en/01-disclaimer/>> >> >> >> ******************************************************************* >> ************************************************* >> >> This message may contain confidential information. If you are not the >> intended recipient please inform the sender that you have received >the >> message in error before deleting it. >> Please do not disclose, copy or distribute information in this e-mail >> or take any action in relation to its contents. To do so is strictly >> prohibited and may be unlawful. Thank you for your co-operation. >> >> NHSmail is the secure email and directory service available for all >> NHS staff in England and Scotland. NHSmail is approved for exchanging >> patient data and other sensitive information with NHSmail and other >accredited email services. >> >> For more information and to find out how you can switch, >> https://portal.nhs.net/help/joiningnhsmail> >Osobní údaje: Informace o zpracování a ochraně osobních údajů >obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: >https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information >about processing and protection of business partner’s personal data are >available on website: >https://www.precheza.cz/en/personal-data-protection-principles/>Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou >důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení >odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any >documents attached to it may be confidential and are subject to the >legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/> > > >******************************************************************************************************************** > >This message may contain confidential information. If you are not the >intended recipient please inform the >sender that you have received the message in error before deleting it. >Please do not disclose, copy or distribute information in this e-mail >or take any action in relation to its contents. To do so is strictly >prohibited and may be unlawful. Thank you for your co-operation. > >NHSmail is the secure email and directory service available for all NHS >staff in England and Scotland. NHSmail is approved for exchanging >patient data and other sensitive information with NHSmail and other >accredited email services. > >For more information and to find out how you can switch, >https://portal.nhs.net/help/joiningnhsmail> >______________________________________________ >[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. -- Sent from my phone. Please excuse my brevity. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. Reply | Threaded Open this post in threaded view | ## Re: I can't get seq to behave how I think it should  In reply to this post by R help mailing list-2 > On 17 Jan 2019, at 15:56 , POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST) via R-help <[hidden email]> wrote: > > Well I get the issue with finite precision. As in SQRT(2) * SQRT(2) is not 2. As Jeff indicates, you also need to get that just like 3rds and 7ths cannot be represented exactly in base 10, 5ths and 10ths cannot be represented exactly in base 2 (only powers of 1/2 and their multiples can). Specifically, 1.4 decimal is 1.0110011001100.... binary -pd > > What surprised me was that seq(1.4, 2.1, by=0.001) starts at 1.3999999999999999 and not 1.4! > > > -----Original Message----- > From: PIKAL Petr [mailto:[hidden email]] > Sent: 17 January 2019 14:30 > To: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION TRUST); Ben Tupper > Cc: [hidden email] > Subject: RE: [R] I can't get seq to behave how I think it should > > Hi > > It is not seq problem, it is floating point numbers representation in finit precision problem. Ben pointed to it and you could learn about it from FAQ 7.31. > > Cheers > Petr > >> -----Original Message----- >> From: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS FOUNDATION >> TRUST) <[hidden email]> >> Sent: Thursday, January 17, 2019 2:56 PM >> To: PIKAL Petr <[hidden email]>; Ben Tupper >> <[hidden email]> >> Cc: [hidden email] >> Subject: RE: [R] I can't get seq to behave how I think it should >> >> Thanks guys. >> >> I've used Petr's method and its working for me. >> >> If the data had been from a calculation I'd have rounded it... just >> didn't expect seq to break it! >> >> C >> >> -----Original Message----- >> From: PIKAL Petr [mailto:[hidden email]] >> Sent: 17 January 2019 13:53 >> To: Ben Tupper; POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS >> FOUNDATION TRUST) >> Cc: [hidden email] >> Subject: RE: [R] I can't get seq to behave how I think it should >> >> Hi >> >> Or you could use rounding. >> which(round(lut, 3)==1.8) >> [1] 401 >> >> Cheers >> Petr >> >>> -----Original Message----- >>> From: R-help <[hidden email]> On Behalf Of Ben Tupper >>> Sent: Thursday, January 17, 2019 2:43 PM >>> To: POLWART, Calum (COUNTY DURHAM AND DARLINGTON NHS >> FOUNDATION TRUST) >>> <[hidden email]> >>> Cc: [hidden email] >>> Subject: Re: [R] I can't get seq to behave how I think it should >>> >>> Hi, >>> >>> This looks like a floating point reality bump - see >>> >>> https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-thin>>> k- these-numbers-are-equal_003f >>> >> FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f> >>> >>> You can use other methods to finding your row - I would opt for >>> findInterval() >>> >>>> lut = seq(1.4, 2.1, by=0.001) >>>> findInterval(1.8, lut) >>> [1] 401 >>> >>> findInterval() uses a rapid search to find the index in the look up >>> table (lut) that is just less than or equal to the search value (in >>> your example >> 1.8). >>> >>> Cheers, >>> Ben >>> >>>> On Jan 17, 2019, at 8:33 AM, POLWART, Calum (COUNTY DURHAM AND >>> DARLINGTON NHS FOUNDATION TRUST) via R-help <[hidden email]> >>> wrote: >>>> >>>> I am using seq with the expression seq(1.4, 2.1, by=0.001) to >>>> create a sequence of references from 1.4 to 2.1 in 0.001 >>>> increments. They appear to be created correctly. They have a >>>> related pair of data which for the purposes of this we will call >>>> val. I'm interested in the content on the row with seq = 1.8. But >>>> I can't seem to get it returned. I can get other values but not >>>> 1.8! yet looking at row >>>> 401 there is nothing to indicate an issue >>>> >>>>> a = 1.4 >>>>> b = 2.1 >>>>> seq = seq(a, b, by=0.001) >>>>> val = ceiling(seq * 50) >>>>> s=data.frame(seq, val) >>>>> s$val[seq==1.799] >>>> [1] 90 >>>>> s$val[s$seq==1.8] >>>> numeric(0) >>>>> s$val[seq==1.8] >>>> numeric(0) >>>>> s$val[s$seq==1.800] >>>> numeric(0) >>>>> s$val[s$seq==1.801] >>>> [1] 91 >>>>> head(s[s$seq>1.798,]) >>>>     seq val >>>> 400 1.799  90 >>>> 401 1.800  90 >>>> 402 1.801  91 >>>> 403 1.802  91 >>>> 404 1.803  91 >>>> 405 1.804  91 >>>> >>>> >>>> Can anyone explain what's going on here and how I would correctly >>>> find the >>> content of row 401 by using an expression to equal the seq column? >>>> >>>> >>>> >>>> >>>> >>>> >>> >> ******************************************************************* >>> *** >>>> ********************************************** >>>> >>>> This message may contain confidential information. If >>>> ...{{dropped:25}} >>> >>> ______________________________________________ >>> [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. >> Osobní údaje: Informace o zpracování a ochraně osobních údajů >> obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: >> https://www.precheza.cz/zasady- ochrany-osobnich-udaju/ | Information >> about processing and protection of business partner’s personal data are available on website: >> https://www.precheza.cz/en/personal-data-protection-principles/>> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou >> důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: >> https://www.precheza.cz/01-dovetek/ | This email and any documents >> attached to it may be confidential and are subject to the legally >> binding >> disclaimer: https://www.precheza.cz/en/01-disclaimer/>> >> >> >> ******************************************************************* >> ************************************************* >> >> This message may contain confidential information. If you are not the >> intended recipient please inform the sender that you have received the >> message in error before deleting it. >> Please do not disclose, copy or distribute information in this e-mail >> or take any action in relation to its contents. To do so is strictly >> prohibited and may be unlawful. Thank you for your co-operation. >> >> NHSmail is the secure email and directory service available for all >> NHS staff in England and Scotland. NHSmail is approved for exchanging >> patient data and other sensitive information with NHSmail and other accredited email services. >> >> For more information and to find out how you can switch, >> https://portal.nhs.net/help/joiningnhsmail> > Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/> > > > ******************************************************************************************************************** > > This message may contain confidential information. If you are not the intended recipient please inform the > sender that you have received the message in error before deleting it. > Please do not disclose, copy or distribute information in this e-mail or take any action in relation to its contents. To do so is strictly prohibited and may be unlawful. Thank you for your co-operation. > > NHSmail is the secure email and directory service available for all NHS staff in England and Scotland. NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and other accredited email services. > > For more information and to find out how you can switch, https://portal.nhs.net/help/joiningnhsmail> > ______________________________________________ > [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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: [hidden email]  Priv: [hidden email] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|