Re: [R] sort question in a dataset?

From: Richard M. Heiberger <>
Date: Sun 15 Oct 2006 - 05:31:53 GMT

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)
tmp[order(tmp)] mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Sun Oct 15 15:35:25 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 - 06:30:10 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.