[R] order()
E. D. Isaia
isaia at econ.unito.it
Sat Mar 30 05:58:08 CET 2002
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list