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:> 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 theWhat 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.> previous condition "a ascending, b descending, c descending". How can I > do this?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. -- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
If it helps:> x<-c(5,6,7,4,3,2,1) > y<-x^2 > mydata <- cbind(x,y) > (mydata <- mydata[order(mydata[,1]),])x y [1,] 1 1 [2,] 2 4 [3,] 3 9 [4,] 4 16 [5,] 5 25 [6,] 6 36 [7,] 7 49> x <- mydata[,1] > y <- mydata[,2]Best, isaia. Ko-Kang Kevin Wang wrote:> 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._