sortWith
Returns the sorted version of the current ValueColumn, FrameColumn, or ColumnGroup based on the given Comparator. The comparator can either be given as an instance of Comparator, or directly as a lambda.
For example
df["price"].sortWith{ a, b -> a - b }
df.select{
name.sortWith(myComparator) andallAfter(name)
}
For more information: See sortWith on the documentation website.
Receiver
The DataColumn to sort. This can be either a ValueColumn, FrameColumn, or ColumnGroup and will dictate the return type of the function.
Return
The sorted DataColumn this of the same type as the receiver.
Parameters
The Comparator to use for sorting the DataColumn. This can either be a Comparator<T> or a lambda of type (T, T) -> Int.
Sorts the rows of this DataFrame using the specified row comparator.
Returns a new DataFrame containing the same rows sorted according to the provided Comparator.
See also sortBy and sortByDesc, which sort rows by selected columns.
Example
// Provide a comparator for `DataRow<Person>` that sorts
// by `age` in ascending order first
// and then by `salary` in descending order
df.sortWith(
compareBy<DataRow<Person>> { it.age }
.thenByDescending { it.salary }
)Return
A new DataFrame containing the same rows sorted according to the provided comparator.
Parameters
The Comparator used to determine the order of rows.
Sorts the rows of this DataFrame using the specified row comparator.
The comparator is a comparison lambda that takes two DataRows and returns a negative, zero, or positive value depending on their relative order.
Returns a new DataFrame containing the same rows sorted according to the provided comparator.
See also sortBy and sortByDesc, which sort rows by selected columns.
Example
// Sort by `age` in ascending order,
// then by `salary` in ascending order
df.sortWith { row1, row2 ->
when {
row1.age != row2.age -> row1.age.compareTo(row2.age)
else -> row1.salary.compareTo(row2.salary)
}
}Return
A new DataFrame containing the same rows sorted according to the provided comparator.
Parameters
A function that compares two rows and returns a negative, zero, or positive value depending on their relative order.