Skip to content

order()

3 messages · Ko-Kang Kevin Wang, Brian Ripley, E. D. Isaia

#
Hi,

In the order() help file, there is an example like:
     a <- c(4, 3, 2, NA, 1)
     b <- c(4, NA, 2, 7, 1)
     z <- cbind(a, b)
     (o <- order(a, b)); z[o, ]

How can I do something like "order a in ascending order, b in descending
order"?  And say I have a third vector c, and I'd like to add this to the
previous condition "a ascending, b descending, c descending".  How can I
do this?

Thanks,

Ko-Kang Wang

------------------------------------------------------------------------------
Ko-Kang Kevin Wang
Postgraduate PGDipSci Student
Department of Statistics
University of Auckland
New Zealand

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Fri, 29 Mar 2002, Ko-Kang Kevin Wang wrote:

            
What order does is to use lexicopgraphic order, that is order by a, break
ties by b.  As from 1.5.0 it will allow decreasing ordering, but for all
columns.
Only (at all easily) by arranging b and c to be in reverse order, for
examply by using -b if b is numeric.  And you can easily do this, since

order(a, b) = order(rank(a), rank(b))

so in your example use

order(a, -rank(b), -rank(c))

I'd be intrigued to know why you want this.
#
If it helps:
x  y
[1,] 1  1
[2,] 2  4
[3,] 3  9
[4,] 4 16
[5,] 5 25
[6,] 6 36
[7,] 7 49
Best, isaia.
Ko-Kang Kevin Wang wrote:

            
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Ennio D. Isaia
~ Dep. of Statistics & Mathematics, University of Torino
~ Piazza Arbarello, 8 - 10128 Torino (Italy)
~ Phone: +39 011 670 62 51 ~~ Fax: +39 011 670 62 39
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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