Sorts a data frame by one or more variables.

On this page we will be using the mtcars dataset, which can be loaded by typing data(mtcars) into the Console.


To sort data, choose Sort from the Data menu on the menu bar on the Console window. The following window will appear.

Choose the data set to be sorted using the dropdown. In this example, the data frame is mtcars. Other open files can be chosen from the pull down menu.

Choose the variable on which to sort and add it to the Sort data by: space by clicking on the right arrow. To remove a variable from the Sort data by: space use the left arrow. Choose ascending or descending order by clicking on the appropriate button. Data will be sorted by the first variable, with ties broken by subsequent variables.

Click OK. The sorted file will appear in the Data Viewer.

R Code

Running the above yields the following call:

mtcars<- sort(mtcars, by=~ cyl +mpg)