Gabor Grothendieck wrote: > DF <- data.frame(a = c(3, 4, 2, 3, 2, 4, 2), b = 7:1)) > DF[do.call(order, DF),] > > will sort on all the columns. ... and you can use
DF[do.call(order, DF[names]),] if you have the column names in a character vector. > > On 11/28/06, michael watson (IAH-C) <[EMAIL PROTECTED]> wrote: >> Hi >> >> Sorry to ask such a well oiled question, but even with multiple google hits >> I don't think this has been answered very well. >> >> It's all well and good doing a sort of a data frame on multiple columns when >> you know in advance which columns you want to sort on, but what about when >> the names of the columns you wish to sort on are in a vector? >> >> At the minute I'm messing about with paste() to form a string that works for >> order() and then calling do.call(). Is this really the best way of doing it? >> >> Thanks >> Mick >> >> ______________________________________________ >> 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. -- O__ ---- Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 ______________________________________________ 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.