meanOf

inline fun <T, reified R : Number?> DataColumn<T>.meanOf(skipNaN: Boolean = skipNaNDefault, crossinline expression: (T) -> R): Double

Returns the mean of the values that the given expression returns for each element of this DataColumn, as a Double.

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

All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (BigInteger, BigDecimal) are not supported; convert them to a primitive number type first.

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.

The resulting average is always a Double and never null. Converting Long values to Double may lose precision for very large values.

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

When there is nothing to average, for instance, when the input is empty or contains only null values, the result is Double.NaN.

See also:

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

  • sumOf — the sum of the values returned by an expression.

  • The Mean Operation — an overview of all mean modes.

For more information: See mean on the documentation website.

Example

// The mean length of all first names in the "name"/"firstName" column
df.name.firstName.meanOf { it.length }

Return

The mean of the values expression returns, as a Double.

Parameters

expression

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

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 D : Number?> DataFrame<T>.meanOf(skipNaN: Boolean = skipNaNDefault, crossinline expression: RowExpression<T, D>): Double

Returns the mean of the values that the given expression returns for each row of this DataFrame, as a Double.

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.

All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (BigInteger, BigDecimal) are not supported; convert them to a primitive number type first.

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.

The resulting average is always a Double and never null. Converting Long values to Double may lose precision for very large values.

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

When there is nothing to average, for instance, when the input is empty or contains only null values, the result is Double.NaN.

See also:

  • mean{ columns } — a single mean of means of the selected columns.

  • sumOf — the sum of those values.

  • The Mean Operation — an overview of all mean modes.

For more information: See mean on the documentation website.

Example

// The mean of the weight-to-age ratios of all rows
df.meanOf { (weight ?: 0) / age }

Return

The mean of the values expression returns, 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.

expression

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


inline fun <T, reified R : Number?> Grouped<T>.meanOf(name: String? = null, skipNaN: Boolean = skipNaNDefault, crossinline expression: RowExpression<T, R>): DataFrame<T>

Aggregates this GroupBy by computing the mean of the values that the given expression returns for each row of a group.

Returns a new DataFrame with one row per group, containing the group key columns and a single column with the mean per group, named name (or "mean" if name is null).

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.

All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (BigInteger, BigDecimal) are not supported; convert them to a primitive number type first.

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.

The resulting average is always a Double and never null. Converting Long values to Double may lose precision for very large values.

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

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

See also:

  • mean — a single mean of means of the selected columns, per group.

  • sumOf — the sum of those values, per group.

  • aggregate — the general way to aggregate groups.

  • The Mean Operation — an overview of all mean 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 mean of the weight-to-age ratios, in a column called "meanRatio"
df.groupBy { city }.meanOf("meanRatio") { (weight ?: 0) / age }

Return

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

Parameters

name

The name of the resulting column. If null (the default), "mean" is used. 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.

expression

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


inline fun <T, reified R : Number?> Pivot<T>.meanOf(skipNaN: Boolean = skipNaNDefault, crossinline expression: RowExpression<T, R>): DataRow<T>

Aggregates this Pivot by computing the mean of the values that the given expression returns for each row, per group.

Returns a single DataRow with the pivot keys as (nested) columns, containing the mean of the expression's results for the rows of the corresponding group.

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.

All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (BigInteger, BigDecimal) are not supported; convert them to a primitive number type first.

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.

The resulting average is always a Double and never null. Converting Long values to Double may lose precision for very large values.

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

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

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 mean of the weight-to-age ratios
df.pivot { city }.meanOf { (weight ?: 0) / age }

Return

A single DataRow with, per pivot group, the mean of the expression's results.

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 average for each row.


inline fun <T, reified R : Number?> PivotGroupBy<T>.meanOf(skipNaN: Boolean = skipNaNDefault, crossinline expression: RowExpression<T, R>): DataFrame<T>

Aggregates this PivotGroupBy by computing the mean of the values that the given expression returns for each row, per group.

Returns a DataFrame where each cell contains the mean of the expression's results for the rows of the group corresponding to that pivot key (column) and groupBy key (row).

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.

All primitive number types are supported: Byte, Short, Int, Long, Float, and Double. "Mixed" Number input is supported too, as long as it consists solely of those primitive numbers; its values are then first converted to their common type using UnifiedNumberTypeOptions.PRIMITIVES_ONLY, see number unification. Big numbers (BigInteger, BigDecimal) are not supported; convert them to a primitive number type first.

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.

The resulting average is always a Double and never null. Converting Long values to Double may lose precision for very large values.

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

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

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 mean of the weight-to-age ratios
df.pivot { city }.groupBy { name.lastName }.meanOf { (weight ?: 0) / age }

Return

A DataFrame with, per group, the mean of the expression's results.

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 average for each row.