Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.GSO.4.31.0101121840390.22322-100000@auk.stats>
Date: 2001-01-12T18:42:48Z
From: Brian Ripley
Subject: sorting ascending descending?
In-Reply-To: <Pine.LNX.4.21.0101121937200.32029-100000@artemis.imbe.med.uni-erlangen.de>

On Fri, 12 Jan 2001, Torsten Hothorn wrote:

>
> > HI!
> > By xx[order(xx)] I can sort the array ascendin. How to sort them
> > descending.
> >
> > eg.:
> > > a<-c(2,3,110,23,4)
> > > a[order(a)]
> > [1]   2   3   4  23 110
> >
> > but i wont.
> > [1] 110  23   4   3   2
>
> rev(a[order(a)]
>

Or a[rev(order(a))], which is useful if you want to sort arrays not
vectors (just add a comma or two).

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