[R] what don't I get about numeric/double comparisons in R way?
donahchoo at me.com
donahchoo at me.com
Thu Dec 31 04:41:30 CET 2009
Hi,
I'm pretty much an R noob and I'm missing some paradigm in R I think.
I can't figure our how to compare numerics. here's a transcript of my
tests. Any pointers?
> print(range_sd)
[1] 34.40783
> is.numeric(range_sd)
[1] TRUE
> is.numeric(foo)
[1] TRUE
> is.double(range_sd)
[1] TRUE
> is.double(foo)
[1] TRUE
>
> identical(range_sd, foo)
[1] FALSE
> identical(range_sd, 34.40783)
[1] FALSE
> identical(range_sd, 34.40783, num.eq=FALSE)
[1] FALSE
> identical(range_sd, 34.40783, num.eq=TRUE)
[1] FALSE
> library(RUnit)
Warning message:
package 'RUnit' was built under R version 2.10.1
> checkEquals(range_sd, 34.40783)
Error in checkEquals(range_sd, 34.40783) :
Mean relative difference: 5.79431e-08
> checkEquals(range_sd, foo)
Error in checkEquals(range_sd, foo) :
Mean relative difference: 5.79431e-08
> if( range_sd == 34.40783 ) { print("foo")}
> if( range_sd == "34.40783" ) { print("foo")}
> if( range_sd != "34.40783" ) { print("foo")}
[1] "foo"
> all.equal(range_sd, 34.40783)
[1] "Mean relative difference: 5.79431e-08"
More information about the R-help
mailing list