Re: [R] trouble understanding why ...=="NaN" isn't true
Hi, Andrew, Looks like you're reading the data incorrectly. If using ?read.table or the like, try to add a na.strings = c("NA", "NaN") argument. Second, Bert's comment: use ?is.nan, rather than "==". --sundar Andrew Yee said the following on 5/29/2007 3:39 PM: > Okay, it turns out that there were leading spaces, so that in the data, it > was represented as " NaN", hence the expression =="NaN" was coming back as > false. > > Is there a way to find out preemptively if there are leading spaces? > > Thanks, > Andrew > > > On 5/29/07, Andrew Yee <[EMAIL PROTECTED]> wrote: >> I have the following data: >> >>> dataset[2,"Sample.227"] >> [1]NaN >> 1558 Levels: -0.000 -0.001 -0.002 -0.003 -0.004 -0.005 -0.006 -0.007 - >> 0.008 -0.009 ... 2.000 >> >> >> However, I'm not sure why this expression is coming back as FALSE: >> >>> dataset[2,"Sample.227"]=="NaN" >> [1] FALSE >> >> Similarly: >> >>> dataset[2,"Sample.227"]==NaN >> [1] NA >> >> >> It seems that since "NaN" is represented as a character, this expression >> =="NaN" should be TRUE, but it's returning as FALSE. >> >> Thanks, >> Andrew >> > > [[alternative HTML version deleted]] > > __ > R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] trouble understanding why ...=="NaN" isn't true
1. "NaN" is a character string, **not** NaN; hence is.nan("NaN") yields FALSE. 2. Please read the docs! ?NaN explicitly says: "Do not test equality to NaN, or even use identical, since systems typically have many different NaN values." Bert Gunter Genentech Nonclinical Statistics -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Andrew Yee Sent: Tuesday, May 29, 2007 3:33 PM To: r-help@stat.math.ethz.ch Subject: [R] trouble understanding why ...=="NaN" isn't true I have the following data: > dataset[2,"Sample.227"] [1]NaN 1558 Levels: -0.000 -0.001 -0.002 -0.003 -0.004 -0.005 -0.006 -0.007 -0.008- 0.009 ... 2.000 However, I'm not sure why this expression is coming back as FALSE: > dataset[2,"Sample.227"]=="NaN" [1] FALSE Similarly: > dataset[2,"Sample.227"]==NaN [1] NA It seems that since "NaN" is represented as a character, this expression =="NaN" should be TRUE, but it's returning as FALSE. Thanks, Andrew [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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] trouble understanding why ...=="NaN" isn't true
Okay, it turns out that there were leading spaces, so that in the data, it was represented as " NaN", hence the expression =="NaN" was coming back as false. Is there a way to find out preemptively if there are leading spaces? Thanks, Andrew On 5/29/07, Andrew Yee <[EMAIL PROTECTED]> wrote: > > I have the following data: > > > dataset[2,"Sample.227"] > [1]NaN > 1558 Levels: -0.000 -0.001 -0.002 -0.003 -0.004 -0.005 -0.006 -0.007 - > 0.008 -0.009 ... 2.000 > > > However, I'm not sure why this expression is coming back as FALSE: > > > dataset[2,"Sample.227"]=="NaN" > [1] FALSE > > Similarly: > > > dataset[2,"Sample.227"]==NaN > [1] NA > > > It seems that since "NaN" is represented as a character, this expression > =="NaN" should be TRUE, but it's returning as FALSE. > > Thanks, > Andrew > [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] trouble understanding why ...=="NaN" isn't true
I have the following data: > dataset[2,"Sample.227"] [1]NaN 1558 Levels: -0.000 -0.001 -0.002 -0.003 -0.004 -0.005 -0.006 -0.007 -0.008- 0.009 ... 2.000 However, I'm not sure why this expression is coming back as FALSE: > dataset[2,"Sample.227"]=="NaN" [1] FALSE Similarly: > dataset[2,"Sample.227"]==NaN [1] NA It seems that since "NaN" is represented as a character, this expression =="NaN" should be TRUE, but it's returning as FALSE. Thanks, Andrew [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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.