rowMedianOf

inline fun <reified T : Comparable<T>> DataRow<*>.rowMedianOf(): T

Returns the median of the comparable values of type T in this DataRow.

Only the values in the columns of type T (or T?) are taken into account; all other columns of the row are ignored.

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

This overload is meant for non-number self-comparable types, like String or dates.

Careful: Calling this function with a primitive number type, like <Int>, without passing skipNaN also resolves to this overload, instead of the one returning a Double. The interpolated Double result is then returned as T, which may truncate it or throw a ClassCastException. Pass skipNaN explicitly (like skipNaN = false) to call the overload for numbers.

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:

For more information: See "Row statistics" on the documentation website.

Example

// The median of all `String` values ("name"/"firstName", "name"/"lastName", and "city") in the first row
df.flatten()[0].rowMedianOf<String>()

Return

The median of the values of type T in this row.

Type Parameters

T

The type of the values to include. Only columns of this type are taken into account.

Throws

if there are no values to compute the median of.


inline fun <reified T : Comparable<T>, Number> DataRow<*>.rowMedianOf(skipNaN: Boolean = skipNaNDefault): Double

Returns the median of the numbers of type T in this DataRow, as a Double.

Only the values in the columns of type T (or T?) are taken into account; all other columns of the row are ignored.

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

Careful: To call this overload, skipNaN must be passed explicitly (like skipNaN = false). Without it, a call like <Int> resolves to the overload for comparable values instead, which returns the interpolated result as T, possibly truncating it or throwing a ClassCastException.

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:

For more information: See "Row statistics" on the documentation website.

Example

// The median of all `Int` values ("age" and "weight") in the first row
df[0].rowMedianOf<Int>(skipNaN = false)
// The median of all `Double` values in the first row, ignoring `NaN` values
df[0].rowMedianOf<Double>(skipNaN = true)

Return

The median of the values of type T in this row, 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.

Type Parameters

T

The type of the values to include. Only columns of this type are taken into account.

Throws

if there are no values to compute the median of.