percentileFor

fun <T, C : Comparable<*>?> DataFrame<T>.percentileFor(percentile: Double, skipNaN: Boolean = skipNaNDefault, columns: ColumnsForAggregateSelector<T, C>): DataRow<T>

Returns the given percentile of the values of each selected column of this DataFrame separately.

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.

For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.

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

For more information about the resulting types: See "percentile Type Conversion" on the documentation website.

Result cells for which there is nothing to compute the percentile of (for instance, because the input was empty or contained only null values) simply become null.

The columns are selected with the ColumnsForAggregateSelectionDsl — an extension of the Columns Selection DSL which lets you rename the result of a column with into and supply a default value for columns without any values.

See Selecting Columns.

See also:

  • percentile(percentile) — the same, but for all suitable columns at once.

  • percentile(percentile) { columns } — a single percentile of all values in the selected columns.

  • medianFor — the median (50th percentile) of each selected column.

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

For more information: See percentile on the documentation website.

Example

// A single row with the first quartile of the "age" values and of the "weight" values
df.percentileFor(25.0) { age and weight }
// The same, ignoring `NaN` values, and naming the results explicitly
df.percentileFor(25.0, skipNaN = true) { age into "q1Age" and (weight into "q1Weight") }

Return

A single DataRow with the given percentile of each selected column.

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.

columns

The ColumnsForAggregateSelector used to select the columns to compute the percentile of.


fun <T> DataFrame<T>.percentileFor(percentile: Double, vararg columns: String, skipNaN: Boolean = skipNaNDefault): DataRow<T>

Returns the given percentile of the values of each selected column of this DataFrame separately.

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.

For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.

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

For more information about the resulting types: See "percentile Type Conversion" on the documentation website.

Result cells for which there is nothing to compute the percentile of (for instance, because the input was empty or contained only null values) simply become null.

See Selecting Columns.

See also:

  • percentile(percentile) — the same, but for all suitable columns at once.

  • percentile(percentile) { columns } — a single percentile of all values in the selected columns.

  • medianFor — the median (50th percentile) of each selected column.

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

For more information: See percentile on the documentation website.

Example

// A single row with the first quartile of the "age" values and of the "weight" values
df.percentileFor(25.0, "age", "weight")

Return

A single DataRow with the given percentile of each selected column.

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.

columns

The names of the columns to compute the percentile of. These must be existing columns holding self-comparable values, else an IllegalStateException is thrown.

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.


fun <T, C : Comparable<*>?> Grouped<T>.percentileFor(percentile: Double, skipNaN: Boolean = skipNaNDefault, columns: ColumnsForAggregateSelector<T, C>): DataFrame<T>

Aggregates this GroupBy by computing the given percentile of the values of each selected column separately, per group.

Returns a new DataFrame with one row per group, containing the group key columns and a column with the percentile for each selected column.

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.

For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.

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

For more information about the resulting types: See "percentile Type Conversion" on the documentation website.

Result cells for which there is nothing to compute the percentile of (for instance, because the input was empty or contained only null values) simply become null.

The columns are selected with the ColumnsForAggregateSelectionDsl — an extension of the Columns Selection DSL which lets you rename the result of a column with into and supply a default value for columns without any values.

See Selecting Columns.

See also:

  • percentile(percentile) — the same, but for all suitable columns at once.

  • percentile(percentile) { columns } — a single percentile of all values in the selected columns, per group.

  • aggregate — the general way to aggregate groups.

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

For more information: See "groupBy statistics" on the documentation website., and See "GroupBy Aggregation Statistics" on the documentation website.

Example

// For each city, the first quartile of the "age" values and of the "weight" values
df.groupBy { city }.percentileFor(25.0) { age and weight }

Return

A new DataFrame with the group keys and the given percentile of each selected column per group.

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.

columns

The ColumnsForAggregateSelector used to select the columns to compute the percentile of.


fun <T> Grouped<T>.percentileFor(percentile: Double, vararg columns: String, skipNaN: Boolean = skipNaNDefault): DataFrame<T>

Aggregates this GroupBy by computing the given percentile of the values of each selected column separately, per group.

Returns a new DataFrame with one row per group, containing the group key columns and a column with the percentile for each selected column.

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.

For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.

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

For more information about the resulting types: See "percentile Type Conversion" on the documentation website.

Result cells for which there is nothing to compute the percentile of (for instance, because the input was empty or contained only null values) simply become null.

See Selecting Columns.

See also:

  • percentile(percentile) — the same, but for all suitable columns at once.

  • percentile(percentile) { columns } — a single percentile of all values in the selected columns, per group.

  • aggregate — the general way to aggregate groups.

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

For more information: See "groupBy statistics" on the documentation website., and See "GroupBy Aggregation Statistics" on the documentation website.

Example

// For each city, the first quartile of the "age" values and of the "weight" values
df.groupBy { city }.percentileFor(25.0, "age", "weight")

Return

A new DataFrame with the group keys and the given percentile of each selected column per group.

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.

columns

The names of the columns to compute the percentile of. These must be existing columns holding self-comparable values, else an IllegalStateException is thrown.

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.


fun <T, C : Comparable<*>?> Pivot<T>.percentileFor(percentile: Double, separate: Boolean = false, skipNaN: Boolean = skipNaNDefault, columns: ColumnsForAggregateSelector<T, C>): DataRow<T>

Aggregates this Pivot by computing the given percentile of the values of each selected column separately, per group.

Returns a single DataRow with the pivot keys as (nested) columns, containing the percentile of each selected column of the corresponding group.

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.

For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.

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

For more information about the resulting types: See "percentile Type Conversion" on the documentation website.

Result cells for which there is nothing to compute the percentile of (for instance, because the input was empty or contained only null values) simply become null.

The columns are selected with the ColumnsForAggregateSelectionDsl — an extension of the Columns Selection DSL which lets you rename the result of a column with into and supply a default value for columns without any values.

See Selecting Columns, or check out the Pivot Grammar.

See also:

For more information: See "pivot statistics" on the documentation website., and See "Pivot Aggregation statistics" on the documentation website.

Example

// For each city, the first quartile of the "age" values and of the "weight" values
df.pivot { city }.percentileFor(25.0) { age and weight }
// The same, but with the results grouped by aggregated column instead of by city
df.pivot { city }.percentileFor(25.0, separate = true) { age and weight }

Return

A single DataRow with the given percentile of each selected column per pivot group.

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.

separate

If false (the default), the resulting columns are indexed first by the pivot key(s) and then by the names of the aggregated columns. If true, this order is reversed: the results are grouped by aggregated column first.

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.

columns

The ColumnsForAggregateSelector used to select the columns to compute the percentile of.


fun <T> Pivot<T>.percentileFor(percentile: Double, vararg columns: String, separate: Boolean = false, skipNaN: Boolean = skipNaNDefault): DataRow<T>

Aggregates this Pivot by computing the given percentile of the values of each selected column separately, per group.

Returns a single DataRow with the pivot keys as (nested) columns, containing the percentile of each selected column of the corresponding group.

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.

For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.

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

For more information about the resulting types: See "percentile Type Conversion" on the documentation website.

Result cells for which there is nothing to compute the percentile of (for instance, because the input was empty or contained only null values) simply become null.

See Selecting Columns, or check out the Pivot Grammar.

See also:

For more information: See "pivot statistics" on the documentation website., and See "Pivot Aggregation statistics" on the documentation website.

Example

// For each city, the first quartile of the "age" values and of the "weight" values
df.pivot { city }.percentileFor(25.0, "age", "weight")

Return

A single DataRow with the given percentile of each selected column per pivot group.

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.

columns

The names of the columns to compute the percentile of. These must be existing columns holding self-comparable values, else an IllegalStateException is thrown.

separate

If false (the default), the resulting columns are indexed first by the pivot key(s) and then by the names of the aggregated columns. If true, this order is reversed: the results are grouped by aggregated column first.

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.


fun <T, C : Comparable<*>?> PivotGroupBy<T>.percentileFor(percentile: Double, separate: Boolean = false, skipNaN: Boolean = skipNaNDefault, columns: ColumnsForAggregateSelector<T, C>): DataFrame<T>

Aggregates this PivotGroupBy by computing the given percentile of the values of each selected column separately, per group.

Returns a DataFrame where each cell contains the percentile of each selected column of the group corresponding to that pivot key (column) and groupBy key (row).

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.

For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.

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

For more information about the resulting types: See "percentile Type Conversion" on the documentation website.

Result cells for which there exists a group, but there is nothing to compute the percentile of (for instance, because the group was empty or contained only null values) simply become null.

For empty pivot intersections, null or the set default is used.

The columns are selected with the ColumnsForAggregateSelectionDsl — an extension of the Columns Selection DSL which lets you rename the result of a column with into and supply a default value for columns without any values.

See Selecting Columns, or check out the PivotGroupBy Grammar.

See also:

For more information: See "pivot statistics" on the documentation website., and See "Pivot Aggregation statistics" on the documentation website.

Example

// Per city and last name, the first quartile of the "age" values and of the "weight" values
df.pivot { city }.groupBy { name.lastName }.percentileFor(25.0) { age and weight }

Return

A DataFrame with the given percentile of each selected column per pivot and groupBy group.

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.

separate

If false (the default), the resulting columns are indexed first by the pivot key(s) and then by the names of the aggregated columns. If true, this order is reversed: the results are grouped by aggregated column first.

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.

columns

The ColumnsForAggregateSelector used to select the columns to compute the percentile of.


fun <T> PivotGroupBy<T>.percentileFor(percentile: Double, vararg columns: String, separate: Boolean = false, skipNaN: Boolean = skipNaNDefault): DataFrame<T>

Aggregates this PivotGroupBy by computing the given percentile of the values of each selected column separately, per group.

Returns a DataFrame where each cell contains the percentile of each selected column of the group corresponding to that pivot key (column) and groupBy key (row).

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.

For primitive numbers, the resulting percentile is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large values. For all other self-comparable values, the resulting percentile is selected from the values using quantile estimation method R3, so it has the same type as those values.

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

For more information about the resulting types: See "percentile Type Conversion" on the documentation website.

Result cells for which there exists a group, but there is nothing to compute the percentile of (for instance, because the group was empty or contained only null values) simply become null.

For empty pivot intersections, null or the set default is used.

See Selecting Columns, or check out the PivotGroupBy Grammar.

See also:

For more information: See "pivot statistics" on the documentation website., and See "Pivot Aggregation statistics" on the documentation website.

Example

// Per city and last name, the first quartile of the "age" values and of the "weight" values
df.pivot { city }.groupBy { name.lastName }.percentileFor(25.0, "age", "weight")

Return

A DataFrame with the given percentile of each selected column per pivot and groupBy group.

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.

columns

The names of the columns to compute the percentile of. These must be existing columns holding self-comparable values, else an IllegalStateException is thrown.

separate

If false (the default), the resulting columns are indexed first by the pivot key(s) and then by the names of the aggregated columns. If true, this order is reversed: the results are grouped by aggregated column first.

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.


fun <T, C : Comparable<*>?> DataFrame<T>.percentileFor(percentile: Double, vararg columns: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): DataRow<T>
fun <T, C : Comparable<*>?> DataFrame<T>.percentileFor(percentile: Double, vararg columns: KProperty<C>, skipNaN: Boolean = skipNaNDefault): DataRow<T>
fun <T, C : Comparable<*>?> Grouped<T>.percentileFor(percentile: Double, vararg columns: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): DataFrame<T>
fun <T, C : Comparable<*>?> Grouped<T>.percentileFor(percentile: Double, vararg columns: KProperty<C>, skipNaN: Boolean = skipNaNDefault): DataFrame<T>
fun <T, C : Comparable<*>?> Pivot<T>.percentileFor(percentile: Double, vararg columns: ColumnReference<C>, separate: Boolean = false, skipNaN: Boolean = skipNaNDefault): DataRow<T>
fun <T, C : Comparable<*>?> Pivot<T>.percentileFor(percentile: Double, vararg columns: KProperty<C>, separate: Boolean = false, skipNaN: Boolean = skipNaNDefault): DataRow<T>
fun <T, C : Comparable<*>?> PivotGroupBy<T>.percentileFor(percentile: Double, vararg columns: ColumnReference<C>, separate: Boolean = false, skipNaN: Boolean = skipNaNDefault): DataFrame<T>
fun <T, C : Comparable<*>?> PivotGroupBy<T>.percentileFor(percentile: Double, vararg columns: KProperty<C>, separate: Boolean = false, skipNaN: Boolean = skipNaNDefault): DataFrame<T>

Deprecated

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