Dear all, is there an easy way to sort or get the order of a matrix or data.frame by multiple rows (like ODER BY in SQL), that means if some values in the first column are equal, then sort them (or 'order') by the second etc.? Thanks in advance! Michael -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Michael Dondrup <Michael.Dondrup at Genetik.Uni-Bielefeld.DE> writes:> Dear all, > > is there an easy way to sort or get the order of a matrix or data.frame > by multiple rows > (like ODER BY in SQL), that means if some values in the first column are > equal, then sort them (or 'order') by the second etc.?Oder was? (Sorry) Try d[order(d$var1,d$var2,d$var3),] or d[with(d,order(var1,var2,var3)),] The latter form is useful if d is called something longer than "d"... The only mildly annoying thing is that you cannot (easily) sort descending on character variables -- for numeric ones, just switch the sign. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Michael Dondrup wrote:> > Dear all, > > is there an easy way to sort or get the order of a matrix or data.frame > by multiple rows > (like ODER BY in SQL), that means if some values in the first column are > equal, then sort them (or 'order') by the second etc.?What about looking in the help files? My first idea would be to take a look at ?sort and ?order, two words you already mentioned in your querstion. And I'd bet you'll get the answer. Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._