median

fun <T : Comparable<T & Any>?> DataColumn<T>.median(): T & Any

Returns the median of the comparable values in this DataColumn.

This overload is meant for non-number self-comparable values, like strings or dates. Columns of primitive numbers use the median overload with a skipNaN parameter, which returns an interpolated Double.

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.

Throws a NoSuchElementException when there is nothing to compute the median of, for instance, when the input is empty or contains only null values.

The resulting median is selected from the values using quantile estimation method R3, so it has the same type as the values (minus nullability, if the values were nullable).

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 "median Type Conversion" on the documentation website.

See also:

  • medianOrNull — returns null instead of throwing for a column with nothing to compute the median of.

  • medianOf — the median of the values an expression returns for each element.

  • medianBy — the element at the median of the values a selector returns.

  • percentile — any other percentile of the values in this column.

  • The Median Operation — an overview of all median modes.

For more information: See median on the documentation website.

Example

// The median first name in the "name"/"firstName" column (in alphabetical order)
df.name.firstName.median()

Return

The median of the values in this column.

Throws

if there are no values to compute the median of.


fun <T : Comparable<T & Any>?, Number?> DataColumn<T>.median(skipNaN: Boolean = skipNaNDefault): Double

Returns the median of the numbers in this DataColumn, as a Double.

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.

Throws a NoSuchElementException when there is nothing to compute the median of, for instance, when the input is empty or contains only null values.

The resulting median is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large 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.

Big numbers (BigInteger, BigDecimal) are not explicitly supported. They are self-comparable, so some overloads select a value without interpolating it, while others throw an exception at runtime. Don't rely on this; convert them to a primitive number type first.

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

See also:

  • medianOrNull — returns null instead of throwing for a column with nothing to compute the median of.

  • medianOf — the median of the values an expression returns for each element.

  • medianBy — the element at the median of the values a selector returns.

  • percentile — any other percentile of the values in this column.

  • mean — the average of the values in this column.

  • The Median Operation — an overview of all median modes.

For more information: See median on the documentation website.

Example

// The median age in the "age" column
df.age.median()
// The median weight in the "weight" column, ignoring `NaN` values
df.weight.median(skipNaN = true)

Return

The median of the values in this column, as a Double.

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.

Throws

if there are no values to compute the median of.


fun <T> DataFrame<T>.median(skipNaN: Boolean = skipNaNDefault): DataRow<T>

Returns the median of the values of each suitable column of this DataFrame separately.

All columns whose values are mutually comparable are taken into account; the other columns are simply left out of the result.

Columns inside column groups are also excluded. To include those in the median, flatten the DataFrame first.

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 median 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 median 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 "median Type Conversion" on the documentation website.

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

See also:

  • medianFor — the same, but for an explicit selection of columns.

  • median{ columns } — a single median of all values in the selected columns.

  • percentile — any other percentile of each column.

  • The Median Operation — an overview of all median modes.

For more information: See median on the documentation website.

Example

// A single row with the median value of each comparable column
// ("name"/"firstName", "name"/"lastName", "age", "city", "weight", and "isHappy")
df.flatten().median()

Return

A single DataRow with the median of each suitable column of this DataFrame.

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.


fun <T, C : Comparable<C & Any>?> DataFrame<T>.median(columns: ColumnsSelector<T, C>): C & Any

Returns a single median of all the comparable values in the selected columns of this DataFrame.

This overload is meant for non-number self-comparable values, like strings or dates. For columns of primitive numbers, the median overload with a skipNaN parameter is used, which returns an interpolated Double.

Note: Due to a limitation in Kotlin's overload resolution (KT-76683), calling this overload with a lambda returning non-number comparable values, like strings or dates, requires either explicit type arguments, or passing the lambda inside the parentheses (see the examples below). For a lambda returning primitive numbers, the overload returning a Double is picked automatically.

From Kotlin 2.5, this limitation can be lifted by enabling eager lambda analysis (KT-51107) with the compiler option -XXLanguage:+EagerLambdaAnalysis, like kotlin { compilerOptions { freeCompilerArgs.add("-XXLanguage:+EagerLambdaAnalysis") } } in Gradle. Then, the right overload is picked for lambdas returning non-number comparable values too, without explicit type arguments. Note that this is an internal compiler option without any stability guarantees, so it is not recommended for production use yet.

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.

Throws a NoSuchElementException when there is nothing to compute the median of, for instance, when the input is empty or contains only null values.

The resulting median is selected from the values using quantile estimation method R3, so it has the same type as the values (minus nullability, if the values were nullable).

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 "median Type Conversion" on the documentation website.

See also:

  • medianOrNull — returns null instead of throwing when there's nothing to compute the median of.

  • medianFor — the median of each selected column separately.

  • medianOf — the median of the values a row expression returns for each row.

  • percentile — any other percentile of all values in the selected columns.

  • The Median Operation — an overview of all median modes.

For more information: See median on the documentation website.

Select or express columns using the Columns Selection DSL.

This DSL is initiated by a Columns Selector lambda, which operates in the context of the Columns Selection DSL and expects you to return a SingleColumn or ColumnSet (so, a ColumnsResolver). This is an entity formed by calling any (combination) of the functions in the DSL that is or can be resolved into one or more columns.

The Columns Selection DSL allows using Extension Properties for specifying columns type- and name-safe.

Check out: Columns Selection DSL Grammar

    

See Column Selectors on the documentation website.

Examples

// The median of all first and last names in the "name" column group
df.median<_, String> { name.firstName and name.lastName }
// The same, with the lambda inside the parentheses
df.median({ name.firstName and name.lastName })

Return

The median of all the values in the selected columns.

Parameters

columns

The ColumnsSelector used to select the columns to compute the median of.

Throws

if there are no values to compute the median of.


fun <T, C : Number?, Comparable<C & Any>?> DataFrame<T>.median(skipNaN: Boolean = skipNaNDefault, columns: ColumnsSelector<T, C>): Double

Returns a single median of all the numbers in the selected columns of this DataFrame, as a Double.

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.

Throws a NoSuchElementException when there is nothing to compute the median of, for instance, when the input is empty or contains only null values.

The resulting median is a Double, interpolated between the values using quantile estimation method R8. Converting Long values to Double may lose precision for very large 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.

Big numbers (BigInteger, BigDecimal) are not explicitly supported. They are self-comparable, so some overloads select a value without interpolating it, while others throw an exception at runtime. Don't rely on this; convert them to a primitive number type first.

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

See also:

  • medianOrNull — returns null instead of throwing when there's nothing to compute the median of.

  • medianFor — the median of each selected column separately.

  • medianOf — the median of the values a row expression returns for each row.

  • percentile — any other percentile of all values in the selected columns.

  • The Median Operation — an overview of all median modes.

For more information: See median on the documentation website.

Select or express columns using the Columns Selection DSL.

This DSL is initiated by a Columns Selector lambda, which operates in the context of the Columns Selection DSL and expects you to return a SingleColumn or ColumnSet (so, a ColumnsResolver). This is an entity formed by calling any (combination) of the functions in the DSL that is or can be resolved into one or more columns.

The Columns Selection DSL allows using Extension Properties for specifying columns type- and name-safe.

Check out: Columns Selection DSL Grammar

    

See Column Selectors on the documentation website.

Example

// The median of all values in the "age" and "weight" columns
df.median { age and weight }

Return

The median of all the values in the selected columns, as a Double.

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.

columns

The ColumnsSelector used to select the columns to compute the median of.

Throws

if there are no values to compute the median of.


fun <T> DataFrame<T>.median(vararg columns: String, skipNaN: Boolean = skipNaNDefault): Any

Returns a single median of all the values in the columns of this DataFrame with the given names.

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.

Throws a NoSuchElementException when there is nothing to compute the median of, for instance, when the input is empty or contains only null values.

For primitive numbers, the resulting median 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 median 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 "median Type Conversion" on the documentation website.

See also:

  • medianOrNull — returns null instead of throwing when there's nothing to compute the median of.

  • medianFor — the median of each selected column separately.

  • percentile — any other percentile of all values in the selected columns.

  • The Median Operation — an overview of all median modes.

For more information: See median on the documentation website.

Select single or multiple columns using their names as Strings. (String API).

Example

// The median of all values in the "age" and "weight" columns, as a `Double`
df.median("age", "weight")

Return

The median of all the values in the selected columns.

Parameters

columns

The names of the columns to compute the median of. These must be existing columns whose values are mutually comparable, 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.

Throws

if there are no values to compute the median of.


fun <T> Grouped<T>.median(skipNaN: Boolean = skipNaNDefault): DataFrame<T>

Aggregates this GroupBy by computing the median of the values of each suitable column separately, per group.

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

All columns whose values are mutually comparable are taken into account; the other columns are simply left out of the result.

Columns inside column groups are also excluded. To include those in the median, flatten the DataFrame first.

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 median 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 median 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 "median Type Conversion" on the documentation website.

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

See also:

  • medianFor — the same, but for an explicit selection of columns.

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

  • percentile — any other percentile of each column, per group.

  • aggregate — the general way to aggregate groups.

  • The Median Operation — an overview of all median 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 median value of each comparable column
df.groupBy { city }.median()

Return

A new DataFrame with the group keys and the median of each suitable column per group.

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.


fun <T, C : Comparable<C & Any>?> Grouped<T>.median(name: String? = null, skipNaN: Boolean = skipNaNDefault, columns: ColumnsSelector<T, C>): DataFrame<T>

Aggregates this GroupBy by computing a single median of all the values in the selected columns, per group.

Returns a new DataFrame with one row per group, containing the group key columns and a single column with the median per group. That column is named name, or, if name is null, after the selected column if exactly one column is selected, and "median" otherwise.

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 median 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 median 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 "median Type Conversion" on the documentation website.

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

See Selecting Columns.

See also:

  • medianFor — the median of each selected column separately, per group.

  • medianOf — the median of the values a row expression returns for each row of a group.

  • aggregate — the general way to aggregate groups.

  • The Median Operation — an overview of all median 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 median of all values in the "age" and "weight" columns,
// in a column called "medianValue"
df.groupBy { city }.median("medianValue") { age and weight }

Return

A new DataFrame with the group keys and a single median per group.

Parameters

name

The name of the resulting column. If null (the default), the name of the selected column is used if exactly one column is selected, and "median" otherwise. This name needs to be unique, else a DuplicateColumnPathInsertException 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.

columns

The ColumnsSelector used to select the columns to compute the median of.


fun <T> Grouped<T>.median(vararg columns: String, name: String? = null, skipNaN: Boolean = skipNaNDefault): DataFrame<T>

Aggregates this GroupBy by computing a single median of all the values in the selected columns, per group.

Returns a new DataFrame with one row per group, containing the group key columns and a single column with the median per group. That column is named name, or, if name is null, after the selected column if exactly one column is selected, and "median" otherwise.

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 median 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 median 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 "median Type Conversion" on the documentation website.

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

See Selecting Columns.

See also:

  • medianFor — the median of each selected column separately, per group.

  • medianOf — the median of the values a row expression returns for each row of a group.

  • aggregate — the general way to aggregate groups.

  • The Median Operation — an overview of all median 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 median of all values in the "age" and "weight" columns,
// in a column called "medianValue"
df.groupBy { city }.median("age", "weight", name = "medianValue")

Return

A new DataFrame with the group keys and a single median per group.

Parameters

columns

The names of the columns to compute the median of. These must be existing columns whose values are mutually comparable, else an IllegalStateException is thrown.

name

The name of the resulting column. If null (the default), the name of the selected column is used if exactly one column is selected, and "median" otherwise. This name needs to be unique, else a DuplicateColumnPathInsertException 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> Pivot<T>.median(separate: Boolean = false, skipNaN: Boolean = skipNaNDefault): DataRow<T>

Aggregates this Pivot by computing the median of the values of each suitable column separately, per group.

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

All columns whose values are mutually comparable are taken into account; the other columns are simply left out of the result.

Columns inside column groups are also excluded. To include those in the median, flatten the DataFrame first.

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 median 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 median 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 "median Type Conversion" on the documentation website.

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

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 median value of each comparable column
df.pivot { city }.median()

Return

A single DataRow with the median of each suitable column per pivot group.

Parameters

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<C & Any>?> Pivot<T>.median(skipNaN: Boolean = skipNaNDefault, columns: ColumnsSelector<T, C>): DataRow<T>

Aggregates this Pivot by computing a single median of all the values in the selected columns, per group.

Returns a single DataRow with the pivot keys as (nested) columns, containing the median of all the values in the selected columns 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 median 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 median 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 "median Type Conversion" on the documentation website.

Result cells for which there is nothing to compute the median 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 median of all values in the "age" and "weight" columns
df.pivot { city }.median { age and weight }

Return

A DataRow with, per pivot group, a single median of all the values in the selected columns.

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.

columns

The ColumnsSelector used to select the columns to compute the median of.


fun <T> Pivot<T>.median(vararg columns: String, skipNaN: Boolean = skipNaNDefault): DataRow<T>

Aggregates this Pivot by computing a single median of all the values in the selected columns, per group.

Returns a single DataRow with the pivot keys as (nested) columns, containing the median of all the values in the selected columns 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 median 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 median 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 "median Type Conversion" on the documentation website.

Result cells for which there is nothing to compute the median 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 median of all values in the "age" and "weight" columns
df.pivot { city }.median("age", "weight")

Return

A DataRow with, per pivot group, a single median of all the values in the selected columns.

Parameters

columns

The names of the columns to compute the median of. These must be existing columns whose values are mutually comparable, 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> PivotGroupBy<T>.median(separate: Boolean = false, skipNaN: Boolean = skipNaNDefault): DataFrame<T>

Aggregates this PivotGroupBy by computing the median of the values of each suitable column separately, per group.

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

All columns whose values are mutually comparable are taken into account; the other columns are simply left out of the result.

Columns inside column groups are also excluded. To include those in the median, flatten the DataFrame first.

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 median 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 median 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 "median Type Conversion" on the documentation website.

Result cells for which there exists a group, but there is nothing to compute the median 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.

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 median value of each comparable column
df.pivot { city }.groupBy { name.lastName }.median()

Return

A DataFrame with the median of each suitable column per pivot and groupBy group.

Parameters

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<C & Any>?> PivotGroupBy<T>.median(skipNaN: Boolean = skipNaNDefault, columns: ColumnsSelector<T, C>): DataFrame<T>

Aggregates this PivotGroupBy by computing a single median of all the values in the selected columns, per group.

Returns a DataFrame where each cell contains the median of all the values in the selected columns 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 median 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 median 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 "median Type Conversion" on the documentation website.

Result cells for which there exists a group, but there is nothing to compute the median 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 median of all values in the "age" and "weight" columns
df.pivot { city }.groupBy { name.lastName }.median { age and weight }

Return

A DataFrame with, per pivot and groupBy group, a single median of all the values in the selected columns.

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.

columns

The ColumnsSelector used to select the columns to compute the median of.


fun <T> PivotGroupBy<T>.median(vararg columns: String, skipNaN: Boolean = skipNaNDefault): DataFrame<T>

Aggregates this PivotGroupBy by computing a single median of all the values in the selected columns, per group.

Returns a DataFrame where each cell contains the median of all the values in the selected columns 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 median 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 median 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 "median Type Conversion" on the documentation website.

Result cells for which there exists a group, but there is nothing to compute the median 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 median of all values in the "age" and "weight" columns
df.pivot { city }.groupBy { name.lastName }.median("age", "weight")

Return

A DataFrame with, per pivot and groupBy group, a single median of all the values in the selected columns.

Parameters

columns

The names of the columns to compute the median of. These must be existing columns whose values are mutually comparable, 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.


@get:JvmName(name = "ColumnDescription_median")
val ColumnsScope<ColumnDescription>.median: DataColumn<Any>
@get:JvmName(name = "ColumnDescription_median")
val DataRow<ColumnDescription>.median: Any
@get:JvmName(name = "NullableColumnDescription_median")
val ColumnsScope<ColumnDescription?>.median: DataColumn<Any?>
@get:JvmName(name = "NullableColumnDescription_median")
val DataRow<ColumnDescription?>.median: Any?


fun <T, C : Comparable<C & Any>?> DataFrame<T>.median(vararg columns: ColumnReference<C>): C & Any
fun <T, C : Comparable<C & Any>?, Number?> DataFrame<T>.median(vararg columns: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): Double
fun <T, C : Comparable<C & Any>?> DataFrame<T>.median(vararg columns: KProperty<C>): C & Any
fun <T, C : Comparable<C & Any>?, Number?> DataFrame<T>.median(vararg columns: KProperty<C>, skipNaN: Boolean = skipNaNDefault): Double
fun <T, C : Comparable<C & Any>?> Grouped<T>.median(vararg columns: ColumnReference<C>, name: String? = null, skipNaN: Boolean = skipNaNDefault): DataFrame<T>
fun <T, C : Comparable<C & Any>?> Grouped<T>.median(vararg columns: KProperty<C>, name: String? = null, skipNaN: Boolean = skipNaNDefault): DataFrame<T>
fun <T, C : Comparable<C & Any>?> Pivot<T>.median(vararg columns: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): DataRow<T>
fun <T, C : Comparable<C & Any>?> Pivot<T>.median(vararg columns: KProperty<C>, skipNaN: Boolean = skipNaNDefault): DataRow<T>
fun <T, C : Comparable<C & Any>?> PivotGroupBy<T>.median(vararg columns: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): DataFrame<T>
fun <T, C : Comparable<C & Any>?> PivotGroupBy<T>.median(vararg columns: KProperty<C>, 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