byDesc
Puts the columns selected by reorder in descending order of the value of the expression and returns a new DataFrame.
The expression is computed for every selected column. The column is passed to it both as the receiver (this) and as the argument (it). The result has to be Comparable.
The selected columns change places only with each other: they take the positions of the selected columns, in the new order. Other columns stay where they are. The values in the columns do not change.
If the selected columns belong to different column groups, they are reordered within their groups, so no column moves to another group.
If exactly one column group is selected, its nested columns are reordered instead. A column group selected together with other columns moves as a whole, and its nested columns keep their order.
Columns for which the expression gives equal results keep their original order.
See Grammar for more details.
For more information: See reorder on the documentation website.
Examples:
val df = dataFrameOf("c", "d", "a", "b")(
3, 4, 1, 2,
1, 1, 1, 1,
)
// "b" has a larger sum than "a", so they change places
df.reorder("a", "b").cast<Int>().byDesc { sum() } // [c, d, b, a]// df: [name[firstName, lastName], age, city, weight, isHappy]
// "name" and "city" have names of the same length, so "name" stays before "city"
df.reorder { age and name and city }.byDesc { it.name().length } // [name, city, age, weight, isHappy]Return
A new DataFrame with the selected columns reordered.
Parameters
The ColumnExpression that gives the value to sort the selected columns by.