Skip to content

sorting ascending descending! & THX@coling

3 messages · Wolski, Thomas J Vogels, Peter Dalgaard

#
THX.
You are right!!


 a[order(-1*a)]
[1] 110  23   4   3   2


Eryk
coling wrote:

            
--
Witold Eryk Wolski
Max Plank Institut fuer Molekulare Genetik
Ihnestr73 14195 Berlin
Germany
tel.:
Work 0049-30-84131426
http://www.molgen.mpg.de/~wolski


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Witold Eryk Wolski <wolski at molgen.mpg.de> writes:
hmm, I would have thought rev(order(...)) to be more intuitive:

x[order(x)] sorts in ascending order,
x[rev(order(x))] sorts in descending order...

Enjoy,
  -tom
#
Thomas Vogels <tov at ece.cmu.edu> writes:
It is, but the sign trick generalizes to multiple sort criteria:

d[order(d$sex,-d$year,-rank(d$ch)),]

(assuming that d$ch is a character vector which you want to sort by in
reverse alphabetical order).