# [R] Problems with rank()

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Nov 28 13:27:24 CET 2001

```Stephane Hess <S.Hess at statslab.cam.ac.uk> writes:

> If you enter the following values for x and y:
> x: 2.2 3.7 2.1 0.4 2.8 0.3 0.4 1.4 5.4 6.0
> y: 6.0 8.1 1.8 1.3 5.2 0.6 1.0 1.9 6.8 6.5
> and do rank(abs(y-x)),
> you should get two ties, one at 0.3 and one at 0.5.
> R, and S-Plus5 by that matter recognise the tie at 0.5 and give
> it rank 3.5, but gives one of the two 0.3 values rank 1 and one of
> them 2, whereas they should boh be 1.5.
> Any suggestions?
> when you declare a vector with the positive differences manually,
> it ranks them in the correct order.
> if you use rank(sqrt((y-x)^2), it produces the same mistake...

Well,

> (2.1-1.8)-(0.6-0.3)
[1] 5.551115e-17

so to the machine, they are *not* identical. We could introduce a fuzz
factor I suppose, but do we want to.
--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```