Got it, after rtmíng I realized I had to use xtfrm: ord <- order(c(idvars, -xtfrm("t"))) myData[ord, ] It's downright ugly, as it confronts the user with some implementation detail (cf SAS or SPSS), but well, it works. Cheers!! Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ________________________________ To: R Mailing List <r-help@r-project.org> Sent: Tue, January 11, 2011 12:11:01 PM Subject: [R] sorting question Hi, I have a data frame with variables a, b, c (character vars) and t (time var, could be represented as POSIXct or character, depending on which is most useful. The format is "yyyy-mm-dd hh:mm:ss CET"). Now, I want to sort the data frame in ascending order by a, b, c and then in descending order by t. Here's what I've got, but I'm not sure how to put the 'descending' bit in the code. The trick with the minus sign doesn't work as the var isn't numeric. idvars <-- c("a", "b", "c") myData["t"] <- as.POSIXct(myData[,"t"]) result <- myData[ do.call(order, myData[c(idvars, "t")]), ] This should be simple, I guess, but I've been staring at this a bit too long [[elided Yahoo spam]] Cheers!! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [[alternative HTML version deleted]] [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org 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.