percentileByOrNull

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

Returns the element of this DataColumn at the given percentile of the values that the given selector returns for each element, or null if there is nothing to compute the percentile of.

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.

Which value lies at the percentile is determined using quantile estimation method R3, so no interpolation takes place, not even for numbers. If skipNaN is false and NaN values are encountered, the first one with a NaN value is selected.

Currently, only the default quantile estimation methods can be used. In the future, it might become possible to choose a different one, see #1121.

Returns null when there is nothing to compute the percentile of, for instance, when the input is empty or contains only null values.

Don't confuse percentileByOrNull with percentileOfOrNull, which returns the percentile of the selector values itself instead of the element it belongs to.

See also:

  • percentileBy — throws instead of returning null for a column with nothing to compute the percentile of.

  • medianByOrNull — the element at the median (50th percentile) of the values a selector returns.

  • The Percentile Operation — an overview of all percentile modes.

For more information: See percentile on the documentation website.

Example

// The first name at the first quartile of the lengths of all names in the "name"/"firstName" column,
// or `null` if the column is empty
df.name.firstName.percentileByOrNull(25.0) { it.length }

Return

The element at the given percentile of the values selector returns, or null if there are no values to compute the percentile of.

Parameters

percentile

The percentile to compute, in the range [0.0, 100.0], like 25.0 for the first quartile, 50.0 for the median, or 75.0 for the third quartile. A percentile outside this range causes an IllegalStateException.

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>.percentileByOrNull(percentile: Double, skipNaN: Boolean = skipNaNDefault, crossinline expression: RowExpression<T, C>): DataRow<T>?

Returns the row of this DataFrame at the given percentile of the values that the given expression returns for each row, or null if there is nothing to compute the percentile of.

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.

Which value lies at the percentile is determined using quantile estimation method R3, so no interpolation takes place, not even for numbers. If skipNaN is false and NaN values are encountered, the first one with a NaN value is selected.

Currently, only the default quantile estimation methods can be used. In the future, it might become possible to choose a different one, see #1121.

Returns null when there is nothing to compute the percentile of, for instance, when the input is empty or contains only null values.

Don't confuse percentileByOrNull with percentileOfOrNull, which returns the percentile of the expression values itself instead of the row it belongs to.

See also:

  • percentileBy — throws instead of returning null when there's nothing to compute the percentile of.

  • medianByOrNull — the row at the median (50th percentile) of the values a row expression returns.

  • The Percentile Operation — an overview of all percentile modes.

For more information: See percentile on the documentation website.

Example

// The row at the first quartile of "age", or `null` if this dataframe is empty
df.percentileByOrNull(25.0) { age }

Return

The DataRow at the given percentile of the values expression returns, or null if there are no values to compute the percentile of.

Parameters

percentile

The percentile to compute, in the range [0.0, 100.0], like 25.0 for the first quartile, 50.0 for the median, or 75.0 for the third quartile. A percentile outside this range causes an IllegalStateException.

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 the rows by.


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

Returns the row of this DataFrame at the given percentile of the values in the column with the given name, or null if there is nothing to compute the percentile of.

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.

Which value lies at the percentile is determined using quantile estimation method R3, so no interpolation takes place, not even for numbers. If skipNaN is false and NaN values are encountered, the first one with a NaN value is selected.

Currently, only the default quantile estimation methods can be used. In the future, it might become possible to choose a different one, see #1121.

Returns null when there is nothing to compute the percentile of, for instance, when the input is empty or contains only null values.

Don't confuse percentileByOrNull with percentileOrNull, which returns the percentile value itself instead of the row it belongs to.

See also:

  • percentileBy — throws instead of returning null when there's nothing to compute the percentile of.

  • medianByOrNull — the row at the median (50th percentile) of the values in a column.

  • The Percentile Operation — an overview of all percentile modes.

For more information: See percentile on the documentation website.

Example

// The row at the first quartile of "age", or `null` if this dataframe is empty
df.percentileByOrNull(25.0, "age")

Return

The DataRow at the given percentile of the values in the given column, or null if there are no values to compute the percentile of.

Parameters

percentile

The percentile to compute, in the range [0.0, 100.0], like 25.0 for the first quartile, 50.0 for the median, or 75.0 for the third quartile. A percentile outside this range causes an IllegalStateException.

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>.percentileByOrNull(percentile: Double, column: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): DataRow<T>?
inline fun <T, reified C : Comparable<C & Any>?> DataFrame<T>.percentileByOrNull(percentile: Double, 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