How to sort a dataframe by multiple column in R?

Posted by Jessica Taylor | Updated on

How to sort a dataframe by multiple column in R? You can use the order() function directly without resorting to add-on tools — see this simpler answer which uses a trick right from the top of the example(order) code:

Edit some 2+ years later: It was just asked how to do this by column index. The answer is to simply pass the desired sorting column(s) to the order() function:


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers