5.2.8 Sort Data
The ore.sort
function enables flexible sorting of a data frame along one or more columns specified by the by
argument.
The ore.sort
function can be used with other data pre-processing functions. The results of sorting can provide input to R visualization.
The sorting done by the ore.sort
function takes place in the Oracle database. The ore.sort
function supports the database nls.sort
option.
The ore.sort
function returns an ore.frame
.
For details about the function arguments, call help(ore.sort)
.
Most of the following examples use the NARROW
data set. Some examples use the ONTIME_S
data set.
Example 5-51 Sorting Columns in Descending Order
This example sorts the columns AGE and GENDER in descending order.
x <- ore.sort(data=NARROW, by='AGE,GENDER', reverse=TRUE)
Example 5-52 Sorting Different Columns in Different Orders
This example sorts AGE in descending order and GENDER in ascending order.
x <- ore.sort(data=NARROW, by='-AGE,GENDER')
Example 5-53 Sorting and Returning One Row per Unique Value
This example sorts by AGE and keep one row per unique value of AGE:
x <- ore.sort(data=NARROW, by='AGE', unique.key=TRUE)
Example 5-54 Removing Duplicate Columns
This example sorts by AGE and removes duplicate rows:
x <- ore.sort(data=NARROW, by='AGE', unique.data=TRUE)
Example 5-55 Removing Duplicate Columns and Returning One Row per Unique Value
This example sorts by AGE, removes duplicate rows, and returns one row per unique value of AGE.
x <- ore.sort(data=NARROW, by='AGE', unique.data=TRUE, unique.key = TRUE)
Example 5-56 Preserving Relative Order in the Output
This example maintains the relative order in the sorted output.
x <- ore.sort(data=NARROW, by='AGE', stable=TRUE)
Example 5-57 Sorting Two Columns in Different Orders
This example sorts ONTIME_S by airline name in descending order and departure delay in ascending order.
sortedOnTime1 <- ore.sort(data=ONTIME_S, by='-UNIQUECARRIER,DEPDELAY')
Example 5-58 Sorting Two Columns in Different Orders and Producing Unique Combinations
This example sorts ONTIME_S by airline name and departure delay and selects one of each combination (that is, returns a unique key).
sortedOnTime1 <- ore.sort(data=ONTIME_S, by='-UNIQUECARRIER,DEPDELAY', unique.key=TRUE)
Parent topic: Explore Data