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

From: Nick Drew <drewbrewit_at_yahoo.com>
Date: Sun 22 May 2005 - 10:39:31 EST


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"

>



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 10:43:51 2005

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