maxByOrNull

inline fun <T, reified R : Comparable<R & Any>?> DataColumn<T>.maxByOrNull(skipNaN: Boolean = skipNaNDefault, crossinline selector: (T) -> R): T?

Returns the first element of this DataColumn for which the given selector returns the maximum value, or null if there is nothing to compare.

The result of the expression is considered the 'input' of this operation.

Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.

null values in the input are always ignored.

If the input contains NaN values, the result will be NaN, unless skipNaN is set to true.

Returns null when there is nothing left to compare, for instance when the input is empty or contains only null (or, if skipNaN is true, only null and NaN) values.

Don't confuse maxByOrNull with maxOfOrNull, which returns the maximum selector value itself instead of the element it belongs to.

See also:

  • maxBy — throws instead of returning null for a column with nothing to compare.

  • minByOrNull — the mirror operation.

  • The Max Operation — an overview of all max modes.

For more information: See maxBy on the documentation website.

Example

// The longest first name in the "name"/"firstName" column,
// or `null` if the column is empty
df.name.firstName.maxByOrNull { it.length }

Return

The first element for which selector returns the maximum value, or null if there are no values to compare.

Parameters

skipNaN

If true, NaN values are ignored, just like null values. If false (the default), a NaN in the input is propagated to the result. This only has an effect on Double and Float values.

selector

A function that returns the value to compare for each element of this column.


inline fun <T, reified C : Comparable<C & Any>?> DataFrame<T>.maxByOrNull(skipNaN: Boolean = skipNaNDefault, crossinline expression: RowExpression<T, C>): DataRow<T>?

Returns the first row of this DataFrame for which the given expression returns the maximum value, or null if there is nothing to compare.

The given RowExpression is evaluated for each row of the dataframe. The row is both the receiver and the argument (it) of the expression, so the values in it can be accessed directly.

For more information: See RowExpression on the documentation website.

The result of the expression is considered the 'input' of this operation.

Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.

null values in the input are always ignored.

If the input contains NaN values, the result will be NaN, unless skipNaN is set to true.

Returns null when there is nothing left to compare, for instance when the input is empty or contains only null (or, if skipNaN is true, only null and NaN) values.

Don't confuse maxByOrNull with maxOfOrNull, which returns the maximum expression value itself instead of the row it belongs to.

See also:

For more information: See maxBy on the documentation website.

Example

// The row with the largest "age", or `null` if this dataframe is empty
df.maxByOrNull { age }

Return

The first DataRow for which expression returns the maximum value, or null if there are no values to compare.

Parameters

skipNaN

If true, NaN values are ignored, just like null values. If false (the default), a NaN in the input is propagated to the result. This only has an effect on Double and Float values.

expression

The RowExpression to compute the value to compare for each row.


fun <T> DataFrame<T>.maxByOrNull(column: String, skipNaN: Boolean = skipNaNDefault): DataRow<T>?

Returns the first row of this DataFrame that has the largest value in the column with the given name, or null if there is nothing to compare.

Only self-comparable values are supported: values of a type T : Comparable<T> that are mutually comparable (like strings, primitive numbers, or dates). This includes all primitive number types, but no mix of different number types, which would result in a ClassCastException.

null values in the input are always ignored.

If the input contains NaN values, the result will be NaN, unless skipNaN is set to true.

Returns null when there is nothing left to compare, for instance when the input is empty or contains only null (or, if skipNaN is true, only null and NaN) values.

Don't confuse maxByOrNull with maxOfOrNull, which returns the maximum value a row expression returns itself, instead of the row it belongs to.

See also:

  • maxBy — throws instead of returning null when there's nothing to compare.

  • maxOrNull — returns the largest value itself instead of the row it belongs to.

  • minByOrNull — the mirror operation.

  • The Max Operation — an overview of all max modes.

For more information: See maxBy on the documentation website.

Example

// The row with the largest "age", or `null` if this dataframe is empty
df.maxByOrNull("age")

Return

The first DataRow with the largest value in the given column, or null if there are no values to compare.

Parameters

column

The name of the column of this DataFrame to compare the rows by.

skipNaN

If true, NaN values are ignored, just like null values. If false (the default), a NaN in the input is propagated to the result. This only has an effect on Double and Float values.


inline fun <T, reified C : Comparable<C & Any>?> DataFrame<T>.maxByOrNull(column: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): DataRow<T>?
inline fun <T, reified C : Comparable<C & Any>?> DataFrame<T>.maxByOrNull(column: KProperty<C>, skipNaN: Boolean = skipNaNDefault): DataRow<T>?

Deprecated

It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html