sumOf

@JvmName(name = "sumOfShort")
inline fun <C, reified V : Short?> DataColumn<C>.sumOf(crossinline expression: (C) -> V): Int

Returns the sum of the Short values that the given expression returns for each element of this DataColumn, as an Int.

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.

The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.

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

When there is nothing to sum, for instance, when the input is empty or contains only null values, the result is 0 in the result type (defaulting to Double if there is no number type to speak of)

See also:

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

  • meanOf — the sum of those values divided by the number of values.

  • The Sum Operation — an overview of all sum modes.

For more information: See sum on the documentation website.

Example

// The sum of all halved values in the "amount" column of `Short`s, as an `Int`
df.amount.sumOf { (it / 2).toShort() }

Return

The sum of the values expression returns, as an Int.

Parameters

expression

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


@JvmName(name = "sumOfByte")
inline fun <C, reified V : Byte?> DataColumn<C>.sumOf(crossinline expression: (C) -> V): Int

Returns the sum of the Byte values that the given expression returns for each element of this DataColumn, as an Int.

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.

The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.

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

When there is nothing to sum, for instance, when the input is empty or contains only null values, the result is 0 in the result type (defaulting to Double if there is no number type to speak of)

See also:

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

  • meanOf — the sum of those values divided by the number of values.

  • The Sum Operation — an overview of all sum modes.

For more information: See sum on the documentation website.

Example

// The sum of all halved values in the "amount" column of `Byte`s, as an `Int`
df.amount.sumOf { (it / 2).toByte() }

Return

The sum of the values expression returns, as an Int.

Parameters

expression

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


@JvmName(name = "sumOfNumber")
inline fun <C, reified V : Number?> DataColumn<C>.sumOf(skipNaN: Boolean = skipNaNDefault, crossinline expression: (C) -> V): V & Any

Returns the sum of the values that the given expression returns for each element of this DataColumn.

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 result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.

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

When there is nothing to sum, for instance, when the input is empty or contains only null values, the result is 0 in the result type (defaulting to Double if there is no number type to speak of)

See also:

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

  • meanOf — the sum of those values divided by the number of values.

  • The Sum Operation — an overview of all sum modes.

For more information: See sum on the documentation website.

Example

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

Return

The sum of the values expression returns.

Parameters

expression

A function that returns the value to sum 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.


@JvmName(name = "sumOfShort")
inline fun <T, reified C : Short?> DataFrame<T>.sumOf(crossinline expression: RowExpression<T, C>): Int

Returns the sum of the Short values that the given expression returns for each row of this DataFrame, as an Int.

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.

The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.

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

When there is nothing to sum, for instance, when the input is empty or contains only null values, the result is 0 in the result type

See also:

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

  • The Sum Operation — an overview of all sum modes.

For more information: See sum on the documentation website.

Example

// The sum of all halved "amount" values (of `Short`s), as an `Int`
df.sumOf { (amount / 2).toShort() }

Return

The sum of the values expression returns, as an Int.

Parameters

expression

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


@JvmName(name = "sumOfByte")
inline fun <T, reified C : Byte?> DataFrame<T>.sumOf(crossinline expression: RowExpression<T, C>): Int

Returns the sum of the Byte values that the given expression returns for each row of this DataFrame, as an Int.

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.

The result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.

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

When there is nothing to sum, for instance, when the input is empty or contains only null values, the result is 0 in the result type

See also:

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

  • The Sum Operation — an overview of all sum modes.

For more information: See sum on the documentation website.

Example

// The sum of all halved "amount" values (of `Byte`s), as an `Int`
df.sumOf { (amount / 2).toByte() }

Return

The sum of the values expression returns, as an Int.

Parameters

expression

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


@JvmName(name = "sumOfNumber")
inline fun <T, reified C : Number?> DataFrame<T>.sumOf(skipNaN: Boolean = skipNaNDefault, crossinline expression: RowExpression<T, C>): C & Any

Returns the sum of the values that the given expression returns for each row of this DataFrame.

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 result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.

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

When there is nothing to sum, for instance, when the input is empty or contains only null values, the result is 0 in the result type

See also:

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

  • meanOf — the sum of those values divided by the number of values.

  • The Sum Operation — an overview of all sum modes.

For more information: See sum on the documentation website.

Example

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

Return

The sum of the values expression returns.

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


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

Aggregates this GroupBy by computing the sum 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 sum per group, named resultName (or "sum" if resultName 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 result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.

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

Result cells for which there is nothing to sum (for instance, because the input was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).

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

See also:

  • sum — a single sum of all values in the selected columns, per group.

  • meanOf — the sum of those values divided by the number of values, per group.

  • aggregate — the general way to aggregate groups.

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

Return

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

Parameters

resultName

The name of the resulting column. If null (the default), "sum" 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 sum for each row.


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

Aggregates this Pivot by computing the sum 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 sum 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 result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.

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

Result cells for which there is nothing to sum (for instance, because the input was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).

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

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

Return

A single DataRow with, per pivot group, the sum 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 sum for each row.


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

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

Returns a DataFrame where each cell contains the sum 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 result is never null and has the same type as the input, except for Byte and Short, which sum to Int, and "mixed" Number input, which sums to the common type of its values.

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

Result cells for which there exists a group, but there is nothing to sum (for instance, because the group was empty or contained only null values) simply become 0 in the result type (defaulting to Double if there is no number type to speak of).

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

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

Return

A DataFrame with, per group, the sum 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 sum for each row.