Dear All, Is there any simple way to way to produce "rank", for a given list, but in a descending order? E.G: x = list(a=c(1,5,2,4)); rank(x$a); produces 1,4,2,3 However I am looking for a way to generate (4,1,3,2). It would be particularly nice if the proposed solution has all the niceties of rank function (like NA handling and ties.method functionality) TIA Manoj
Here are a couple to try: z <- c(1,5,2,4) rank(-rank(z)) # If z is numeric this can be simplified to: rank(-z) I haven't checked what happens to NAs and ties.method. Manoj - Hachibushu Capital <Wanzare <at> HCJP.com> writes: : : Dear All, : Is there any simple way to way to produce "rank", for a given : list, but in a descending order? : : E.G: : x = list(a=c(1,5,2,4)); : rank(x$a); produces 1,4,2,3 : : However I am looking for a way to generate (4,1,3,2). : : It would be particularly nice if the proposed solution has all : the niceties of rank function (like NA handling and ties.method : functionality) : : TIA : : Manoj
rank((-x$a)) rank() does not work on lists but on numeric vectors, and the above works generally for numeric vectors. On Tue, 20 Apr 2004, Manoj - Hachibushu Capital wrote:> Dear All, > Is there any simple way to way to produce "rank", for a given > list, but in a descending order? > > E.G: > x = list(a=c(1,5,2,4)); > rank(x$a); produces 1,4,2,3 > > However I am looking for a way to generate (4,1,3,2). > > It would be particularly nice if the proposed solution has all > the niceties of rank function (like NA handling and ties.method > functionality)-- 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 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595