Is there a standard way of sorting a data.frame by several columns, but with changes in decrease or increase? For example, you may want to order a data.frame by one variable (decreasing) and by the next (increasing).
Is there something like:
mydf[ order(mydf$myvariable,mydf$myvariable2,decreasing=c(FALSE,TRUE)), ]
library(plyr)
mydf[with(mydf, order(myvariable, desc(myvariable2)), ]
# Or, a little less typing:
arrange(mydf, myvariable, desc(myvariable2))
Quick workaround:
mydf[ order(mydf$myvariable,-mydf$myvariable2,decreasing=F), ]
For factors, strings etc:
mydf[ order(mydf$myvariable,-xtfrm(mydf$myvariable2),decreasing=F), ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With