Re: [R] sort question in a dataset?

From: Christos Hatzis <christos_at_nuverabio.com>
Date: Sun 15 Oct 2006 - 05:41:40 GMT


Another way to do this is:

o <- order(a[,"y"],-a[,"x"], decreasing=TRUE) a[o,]

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Richard M. Heiberger Sent: Sunday, October 15, 2006 1:32 AM
To: zhijie zhang
Cc: R-help@stat.math.ethz.ch
Subject: Re: [R] sort question in a dataset?

Your desired answer just interchanges the sequence of the steps

x <-  c(2, 9, 18, 3, 2)
y <-  c(2,9,8,9,8)
z <-  c(21,5,5,19,7)
a <-  cbind(x, y, z)  #dataset

bb <- a[order(a[,"x"], decreasing=FALSE),] bbb <- bb[order(bb[,"y"], decreasing=TRUE),] bbb

>From ?sort

Sort (or order) a vector or factor (partially) into ascending (or descending) order. For ordering along more than one variable, e.g., for sorting data frames, see order.

>From ?order

order returns a permutation which rearranges its first argument into ascending or descending order, breaking ties by further arguments.

tmp <- c(10,15,12,7)
sort(tmp)
order(tmp)
tmp[order(tmp)]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun Oct 15 15:48:41 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 15 Oct 2006 - 09:30:10 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.