reorderColumnsBy
Puts all columns of the DataFrame in order of the value of the expression and returns a new DataFrame.
The expression is computed for every column. The column is passed to it both as the receiver (this) and as the argument (it). The result has to be Comparable. Columns for which the expression gives equal results keep their original order.
With atAnyDepth set to true (the default), the columns inside every column group are reordered too, each within its own group. With atAnyDepth set to false, only the top-level columns are reordered, and the nested columns keep their order.
The columns inside the dataframes of a frame column keep their order: like colsAtAnyDepth, atAnyDepth does not look inside frame columns. To reorder them too, pass inFrameColumns = true.
The values in the columns do not change.
To reorder only some of the columns, use reorder.
For more information: See reorderColumnsBy on the documentation website.
See also reorderColumnsByName.
Don't confuse it with sortBy, which changes the order of rows, not columns.
Examples:
// df: [name[firstName, lastName], age, city, weight, isHappy]
// Put the columns at any depth in order of the length of their names
df.reorderColumnsBy { name().length } // [age, name[lastName, firstName], city, weight, isHappy]
// Put only the top-level columns in order of the length of their names
df.reorderColumnsBy(atAnyDepth = false) { name().length } // [age, name[firstName, lastName], city, weight, isHappy]Return
A new DataFrame with all columns reordered.
Parameters
If true, the columns inside column groups are reordered too. true by default.
If true, the columns are put in descending order. false by default.
The expression that gives the value to sort the columns by.
Puts all columns of the DataFrame in order of the value of the expression and returns a new DataFrame.
The expression is computed for every column. The column is passed to it both as the receiver (this) and as the argument (it). The result has to be Comparable. Columns for which the expression gives equal results keep their original order.
With atAnyDepth set to true (the default), the columns inside every column group are reordered too, each within its own group. With atAnyDepth set to false, only the top-level columns are reordered, and the nested columns keep their order.
With inFrameColumns set to true, the columns inside every DataFrame of a frame column are reordered too, each dataframe on its own and with the same atAnyDepth. With inFrameColumns set to false, they keep their order: like colsAtAnyDepth, atAnyDepth does not look inside frame columns.
The values in the columns do not change.
To reorder only some of the columns, use reorder.
For more information: See reorderColumnsBy on the documentation website.
See also reorderColumnsByName.
Don't confuse it with sortBy, which changes the order of rows, not columns.
Examples:
// df: [name[firstName, lastName], age, city, weight, isHappy]
// Put the columns at any depth in order of the length of their names
df.reorderColumnsBy { name().length } // [age, name[lastName, firstName], city, weight, isHappy]
// Put only the top-level columns in order of the length of their names
df.reorderColumnsBy(atAnyDepth = false) { name().length } // [age, name[firstName, lastName], city, weight, isHappy]Return
A new DataFrame with all columns reordered.
Parameters
If true, the columns inside column groups are reordered too. true by default.
If true, the columns are put in descending order. false by default.
The expression that gives the value to sort the columns by.
If true, the columns inside frame columns are reordered too.