Re: [R] comparison operator, decimals, and signif()

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Sun 22 May 2005 - 14:40:22 EST

Nick Drew wrote:
> Hi, I recently spent quite a bit of time trouble
> shooting a function that I had written only to
> discover that the problem I was having was with the
> comparison operator. I assumed that the following
> would return TRUE:
>

This is a very common error. In R 2.1.0, it's FAQ

7.31 Why doesn't R think these numbers are equal?

Duncan Murdoch
>

>>testMean <- 82.8 + 0.1
>>testMean

>
> [1] 82.9
>
>>testMean == 82.9

>
> [1] FALSE
>
>
> Apparently this has to do with deciml places. Look:
>
>
>>newTest <- 82.0
>>newTest

>
> [1] 82
>
>>newTest == 82

>
> [1] TRUE
>
>>newTest == 82.0

>
> [1] TRUE
>
>
> What does signif() do to my object called "testMean"
> so that the comparison now evaluates to TRUE?
>
>
>>signif(testMean, 3) == 82.9

>
> [1] TRUE
>
>
> Version info:
>
>
>>R.Version()

>
> $platform
> [1] "i386-pc-mingw32"
>
> $arch
> [1] "i386"
>
> $os
> [1] "mingw32"
>
> $system
> [1] "i386, mingw32"
>
> $status
> [1] ""
>
> $major
> [1] "2"
>
> $minor
> [1] "1.0"
>
> $year
> [1] "2005"
>
> $month
> [1] "04"
>
> $day
> [1] "18"
>
> $language
> [1] "R"
>
>
>
> ______________________________________________
> 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


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 Received on Sun May 22 14:44:32 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:59 EST