[R] one is not one

From: Patrick Giraudoux <patrick.giraudoux_at_univ-fcomte.fr>
Date: Sat 21 Oct 2006 - 09:04:13 GMT


Folks,

I have got a strange behaviour when testing this:

sum(x) != 1

let us set

x<-c(70,134,1,5,0)

and transform it in a vector of probabilities

x<-x/sum(x)

One expect sum(x) should be equal to 1, which is apparently the case

> sum(x)

[1] 1

However, when I try to test it I get:

> if(sum(x) !=1) print("lost") else ("OK")
[1] "lost"

Which means that actually sum(x) is NOT considered equal to 1...

Any idea about what is going wrong?

Patrick



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. Received on Sat Oct 21 20:40:38 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 21 Oct 2006 - 20:30:40 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.