meanOf
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) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, 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:
— the mean of the values in this column itself.mean— the sum of the values returned by an expression.sumOfThe Mean Operation— an overview of allmeanmodes.
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
A function that returns the value to average for each element of this column.
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) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, 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.— the sum of those values.sumOfThe Mean Operation— an overview of allmeanmodes.
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
The RowExpression to compute the value to average for each row.
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) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, 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:
— a single mean of means of the selected columns, per group.mean— the sum of those values, per group.sumOf— the general way to aggregate groups.aggregateThe Mean Operation— an overview of allmeanmodes.
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
The name of the resulting column. If null (the default), "mean" is used. This name needs to be unique, else a DuplicateColumnPathInsertException is thrown.
The RowExpression to compute the value to average for each row.
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) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, 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:
mean{ columns }— a single mean of means of the selected columns, per group.Pivot aggregation— all other ways to aggregate aPivot.The Mean Operation— an overview of allmeanmodes.
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
The RowExpression to compute the value to average for each row.
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) are not supported; BigDecimal them to a primitive number type first.convert
null values in the input are always ignored.
If the input contains values, the result will be NaNNaN, 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:
mean{ columns }— a single mean of means of the selected columns, per group.PivotGroupBy aggregation— all other ways to aggregate aPivotGroupBy.The Mean Operation— an overview of allmeanmodes.
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
The RowExpression to compute the value to average for each row.