[R] order() with randomised order in ties?

Rainer M Krug r.m.krug at gmail.com
Thu Jun 4 12:02:05 CEST 2009


Hi

I want to use order() to get the order of a vector.

But I would need a different behavior when ties occur: similar to the
parameter  ties.method = "random" in the rank() function, I would need
to randomise the ties. Is this possible?

Example:

x <- rep(1:10, 2)
order(x)
 [1]  1 11  2 12  3 13  4 14  5 15  6 16  7 17  8 18  9 19 10 20
order(x)
 [1]  1 11  2 12  3 13  4 14  5 15  6 16  7 17  8 18  9 19 10 20

## I would need different "order" for the ties, as below in rank() example:

rank(x, ties.method="random")
 [1]  1  4  6  7 10 12 13 15 18 19  2  3  5  8  9 11 14 16 17 20
> rank(x, ties.method="random")
 [1]  2  4  5  7  9 12 14 15 18 19  1  3  6  8 10 11 13 16 17 20


Thanks

Rainer

-- 
Rainer M. Krug, Centre of Excellence for Invasion Biology,
Stellenbosch University, South Africa




More information about the R-help mailing list