The steps to use the arrange() verb are very simple and intuitive. The following are the steps:
- Import the dataset into the R environment.
- Call the arrange() function.
- Provide the entire data frame as input.
- Specify the variable names.
Here is the actual code to implement the steps:
arrangeExample <- arrange(USAairlineData2016, ORIGIN, DEST)
- If you are interested to do sorting in descending order, then you must use the desc() function within the arrange() verb as follows:
arrangeExample2 <- arrange(USAairlineData2016, ORIGIN,
desc(DEST))
- The base R alternative code to sort the rows is as follows:
sortRows <- USAairlineData2016[order(USAairlineData2016$ORIGIN,
USAairlineData2016$DEST),]