HI, 2-0.7==0.3 #[1] FALSE ##May be u meant 2-0.7==1.3 #[1] TRUE
Possibly R FAQ 7.31 Also, check http://rwiki.sciviews.org/doku.php?id=misc:r_accuracy all.equal(2-0.7,1.3) #[1] TRUE all.equal(1-0.7,0.3) #[1] TRUE (1-0.7)<(0.3+.Machine$double.eps^0.5) #[1] TRUE p <- c(0.2, 0.4, 0.6, 0.8, 1) round((1-p)*5,1)+1 #[1] 5 4 3 2 1 In your second example, p <- c(0.8, 0.6, 0.4, 0.2, 0) floor((1 - p) * 5) + 1 #[1] 1 3 4 5 6 ((1-0.8)*5) +1 #[1] 2 round((1-p)*5,1)+1 #[1] 2 3 4 5 6 A.K. ...is false :( However (2 - 0.7) == 0.3 is true. Is there any way to get around this? The end goal is for this to work: p <- c(0.2, 0.4, 0.6, 0.8, 1) floor((1 - p) * 5) + 1 > 5 4 3 1 1 whereas the correct result would have been 5 4 3 2 1. If I set p <- c(0.8, 0.6, 0.4, 0.2, 0) then it works as expected. ______________________________________________ R-help@r-project.org 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.