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

Nick Drew drewbrewit at yahoo.com
Sun May 22 02:39:31 CEST 2005


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:

> 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"

>




More information about the R-help mailing list