You don't understand what rank() does: it is not the same as sort.list but
rather the reverse (in the absence of ties).
> x<- c(2,-5,1,3);x
[1] 2 -5 1 3> y <- x
> y[rank(x)] <- x
> y
[1] -5 1 2 3
The ranks are the numbers in the ordering, and -5 is the smallest and so
has rank 1, and so on.
Not a bug at all.
On Wed, 11 May 2005 stella.david@math.uni-augsburg.de wrote:
> Full_Name: Stella David
> Version: 2.1.0
> OS: mingw32
> Submission from: (NULL) (137.250.161.136)
>
>
> It seems that rank doesn't work right on vectors containing negative
values.
> If the negative value is the first component or there are only two
components,
> it works, but if the negative value is somewhere in the middle there's
a
> problem.
>
> Here are my examples:
>> # wrong:
>> x<- c(2,-5,1,3);x
> [1] 2 -5 1 3
>> rank(x)
> [1] 3 1 2 4
>> x[rank(x)]
> [1] 1 2 -5 3
>>
>> # but this works:
>> y<- c(-5,2,1,3);y
> [1] -5 2 1 3
>> rank(y)
> [1] 1 3 2 4
>> y[rank(y)]
> [1] -5 1 2 3
>> z <- c(3,-5);z
> [1] 3 -5
>> rank(z)
> [1] 2 1
>> z[rank(z)]
> [1] -5 3
>>
>> version
> _
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 1.0
> year 2005
> month 04
> day 18
> language R
>
> Stella David
>
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
--
Brian D. Ripley, ripley@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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595