by
Puts the columns selected by reorder in ascending 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.
Example:
val df = dataFrameOf("c", "d", "a", "b")(
3, 4, 1, 2,
1, 1, 1, 1,
)
// "b" has a smaller sum than "d", so they change places
df.reorder("d", "b").cast<Int>().by { sum() } // [c, b, a, d]Return
A new DataFrame with the selected columns reordered.
Parameters
The ColumnExpression that gives the value to sort the selected columns by.
Example:
dataFrameOf("str" to listOf("1 2 3 4"))
.split("str").by("\s+".toRegex())
// when the list of explicitly specified columnNames is not long enough (or none at all),
// names for additional columns are generates
.into()Result:
split1 split2 split3 split4
1 2 3 4