[R] Problems with rank()

Stephane Hess S.Hess at statslab.cam.ac.uk
Wed Nov 28 12:50:25 CET 2001


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...

Stephane Hess,
Statslab Cambridge University 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list