Hi all, I encountered the following strange phenomenon. For some reason, the obs_p[1] and res1$st_p[89] have the same value but when I run "==", it returns FALSE. Can anyone help give some explanation on this? Thanks very much! Hanna> obs_p[1][1] 0.002201438> res1$st_p[89][1] 0.002201438> res1$st_p[89]==obs_p[1][1] FALSE> res1$st_p[89]<obs_p[1][1] FALSE> res1$st_p[89]>obs_p[1][1] TRUE [[alternative HTML version deleted]]
FAQ 7.31 -- Bert 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 Fri, Jan 22, 2016 at 7:46 AM, li li <hannah.hlx at gmail.com> wrote:> Hi all, > I encountered the following strange phenomenon. > For some reason, the obs_p[1] and res1$st_p[89] have > the same value but when I run "==", it returns FALSE. > Can anyone help give some explanation on this? > Thanks very much! > Hanna > >> obs_p[1] > [1] 0.002201438 >> res1$st_p[89] > [1] 0.002201438 >> res1$st_p[89]==obs_p[1] > [1] FALSE >> res1$st_p[89]<obs_p[1] > [1] FALSE >> res1$st_p[89]>obs_p[1] > [1] TRUE > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Hi, This can get you started: cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f --Fabio On Fri, Jan 22, 2016 at 1:46 PM, li li <hannah.hlx at gmail.com> wrote:> Hi all, > I encountered the following strange phenomenon. > For some reason, the obs_p[1] and res1$st_p[89] have > the same value but when I run "==", it returns FALSE. > Can anyone help give some explanation on this? > Thanks very much! > Hanna > > > obs_p[1] > [1] 0.002201438 > > res1$st_p[89] > [1] 0.002201438 > > res1$st_p[89]==obs_p[1] > [1] FALSE > > res1$st_p[89]<obs_p[1] > [1] FALSE > > res1$st_p[89]>obs_p[1] > [1] TRUE > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
On 01/22/2016 10:46 AM, li li wrote:> Hi all, > I encountered the following strange phenomenon. > For some reason, the obs_p[1] and res1$st_p[89] have > the same value but when I run "==", it returns FALSE. > Can anyone help give some explanation on this? > Thanks very much! > Hanna > >> obs_p[1] > [1] 0.002201438 >> res1$st_p[89] > [1] 0.002201438 >> res1$st_p[89]==obs_p[1] > [1] FALSE >> res1$st_p[89]<obs_p[1] > [1] FALSE >> res1$st_p[89]>obs_p[1] > [1] TRUE > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.I believe the decimal representation is only approximate. The real internal values in binary are different. If you want to have comparisons like this result in being considered equal, I think there is a way to use a fuzzy comparison but I don't remember the details. Rick -- Richard A. Bilonick, PhD Assistant Professor Dept. of Ophthalmology, School of Medicine Dept. of Biostatistics, Graduate School of Public Health Dept. of Orthodontics, School of Dental Medicine University of Pittsburgh Principal Investigator for the Pittsburgh Aerosol Research and Inhalation Epidemiology Study (PARIES) 412 647 5756
FAQ 7.31 in this case subtract the two numbers and see that they differ by about 1e-16 Sent from my iPhone> On Jan 22, 2016, at 10:46, li li <hannah.hlx at gmail.com> wrote: > > Hi all, > I encountered the following strange phenomenon. > For some reason, the obs_p[1] and res1$st_p[89] have > the same value but when I run "==", it returns FALSE. > Can anyone help give some explanation on this? > Thanks very much! > Hanna > >> obs_p[1] > [1] 0.002201438 >> res1$st_p[89] > [1] 0.002201438 >> res1$st_p[89]==obs_p[1] > [1] FALSE >> res1$st_p[89]<obs_p[1] > [1] FALSE >> res1$st_p[89]>obs_p[1] > [1] TRUE > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
I see. Thanks! 2016-01-22 10:57 GMT-05:00 Rmh <rmh at temple.edu>:> FAQ 7.31 > > in this case subtract the two numbers and see that > they differ by about 1e-16 > > Sent from my iPhone > > > On Jan 22, 2016, at 10:46, li li <hannah.hlx at gmail.com> wrote: > > > > Hi all, > > I encountered the following strange phenomenon. > > For some reason, the obs_p[1] and res1$st_p[89] have > > the same value but when I run "==", it returns FALSE. > > Can anyone help give some explanation on this? > > Thanks very much! > > Hanna > > > >> obs_p[1] > > [1] 0.002201438 > >> res1$st_p[89] > > [1] 0.002201438 > >> res1$st_p[89]==obs_p[1] > > [1] FALSE > >> res1$st_p[89]<obs_p[1] > > [1] FALSE > >> res1$st_p[89]>obs_p[1] > > [1] TRUE > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]