[R] Problem with ties in rank()
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Tue May 7 20:45:18 CEST 2002
On Tue, 7 May 2002, arcriswell wrote:
> Hello All:
>
> I have a vector of data, z
>
> > z
> [1] 0.1 0.1 0.1 0.1 0.2 0.2 0.3 0.3 0.3 0.4 0.5 0.5 0.5 0.7
> 0.7 0.7 0.9 0.9 1.1
> [20] 1.1 1.2 1.3 1.4
>
> The first 4 elements have values of 0.1 followed 2 elements with values 0.2.
>
> When I invoke rank(z), I expected to get (1+2+3+4)/4 = 2.5 for the first 4
> elements in the ranking and (5+6)/2 = 5.5 for elements 5 and 6. But what I
> do get is the following.
>
> > rank(z)
> [1] 1.5 1.5 3.5 3.5 5.0 6.0 8.0 8.0 8.0 10.0 12.0 12.0 12.0
15.0 15.0
> [16] 15.0 17.5 17.5 19.5 19.5 21.0 22.0 23.0
> >
>
> Why is that???
Rounding error, I guess.
> z <- scan(n=23)
0.1 0.1 0.1 0.1 0.2 0.2 0.3 0.3 0.3 0.4 0.5 0.5 0.5 0.7
0.7 0.7 0.9 0.9 1.1 1.1 1.2 1.3 1.4
> rank(z)
[1] 2.5 2.5 2.5 2.5 5.5 5.5 8.0 8.0 8.0 10.0 12.0 12.0 12.0 15.0 15.0
[16] 15.0 17.5 17.5 19.5 19.5 21.0 22.0 23.0
>
> I am using R 1.5.0 on Windows 2000.
So was I. Try dput(z).
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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