sum

@JvmName(name = "sumShort")
fun DataColumn<Short?>.sum(): Int

Returns the sum of the Short values in this DataColumn, as an Int.

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:

  • sumOf — the sum of the values an expression returns for each element.

  • mean — the sum divided by the number of values.

  • cumSum — the running sum of the values in this column.

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

For more information: See sum on the documentation website.

Example

// The sum of all values in the "amount" column of `Short`s, as an `Int`
df.amount.sum()

Return

The sum of the values in this column, as an Int.


@JvmName(name = "sumByte")
fun DataColumn<Byte?>.sum(): Int

Returns the sum of the Byte values in this DataColumn, as an Int.

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:

  • sumOf — the sum of the values an expression returns for each element.

  • mean — the sum divided by the number of values.

  • cumSum — the running sum of the values in this column.

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

For more information: See sum on the documentation website.

Example

// The sum of all values in the "amount" column of `Byte`s, as an `Int`
df.amount.sum()

Return

The sum of the values in this column, as an Int.


@JvmName(name = "sumNumber")
fun <T : Number?> DataColumn<T>.sum(skipNaN: Boolean = skipNaNDefault): T & Any

Returns the sum of the values in this DataColumn.

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:

  • sumOf — the sum of the values an expression returns for each element.

  • mean — the sum divided by the number of values.

  • cumSum — the running sum of the values in this column.

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

For more information: See sum on the documentation website.

Example

// The sum of all ages in the "age" Int column
df.age.sum()
// The sum of all weights in the "weight" `Double?` column, ignoring `null` values
df.weight.sum()

Return

The sum of the values in this column.

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> DataFrame<T>.sum(skipNaN: Boolean = skipNaNDefault): DataRow<T>

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

All columns of a primitive number type (and all "mixed" Number columns) 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 sum, flatten the DataFrame first.

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:

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

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

  • mean — the sum of each column divided by its number of values.

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

For more information: See sum on the documentation website.

Example

// A single row with the sum of each number column ("age" and "weight")
df.sum()

Return

A single DataRow with the sum 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.


@JvmName(name = "sumShort")
fun <T, C : Short?> DataFrame<T>.sum(columns: ColumnsSelector<T, C>): Int

Returns a single sum of all the Short values in the selected columns of this DataFrame, as an Int.

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)

This can include column groups and nested columns.

See also:

  • sumFor — the sum of each selected column separately.

  • sumOf — the sum of the values a row expression returns for each row.

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

For more information: See sum 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 sum of all values in the "amount" and "bonus" columns of `Short`s, as an `Int`
df.sum { amount and bonus }

Return

The sum of all the values in the selected columns, as an Int.

Parameters

columns

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


@JvmName(name = "sumByte")
fun <T, C : Byte?> DataFrame<T>.sum(columns: ColumnsSelector<T, C>): Int

Returns a single sum of all the Byte values in the selected columns of this DataFrame, as an Int.

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)

This can include column groups and nested columns.

See also:

  • sumFor — the sum of each selected column separately.

  • sumOf — the sum of the values a row expression returns for each row.

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

For more information: See sum 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 sum of all values in the "amount" and "bonus" columns of `Byte`s, as an `Int`
df.sum { amount and bonus }

Return

The sum of all the values in the selected columns, as an Int.

Parameters

columns

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


@JvmName(name = "sumNumber")
fun <T, C : Number?> DataFrame<T>.sum(skipNaN: Boolean = skipNaNDefault, columns: ColumnsSelector<T, C>): C & Any

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

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)

This can include column groups and nested columns.

See also:

  • sumFor — the sum of each selected column separately.

  • sumOf — the sum of the values a row expression returns for each row.

  • mean — the sum divided by the number of values.

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

For more information: See sum 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 sum of all values in the "age" and "weight" columns together
df.sum { age and weight }

Return

The sum 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 sum of.


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

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

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)

This can include column groups and nested columns.

See also:

  • sumFor — the sum of each selected column separately.

  • sumOf — the sum of the values a row expression returns for each row.

  • mean — the sum divided by the number of values.

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

For more information: See sum on the documentation website.

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

Example

// The sum of all values in the "age" and "weight" columns together
df.sum("age", "weight")

Return

The sum of all the values in the selected columns.

Parameters

columns

The names of the columns to compute the sum of. These must be existing primitive number columns, else an IllegalStateException or IllegalArgumentException 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> Grouped<T>.sum(skipNaN: Boolean = skipNaNDefault): DataFrame<T>

Aggregates this GroupBy by computing the sum 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 sum for each suitable column.

All columns of a primitive number type (and all "mixed" Number columns) 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 sum, flatten the DataFrame first.

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:

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

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

  • mean — the sum of each column divided by its 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 each number column ("age" and "weight")
df.groupBy { city }.sum()

Return

A new DataFrame with the group keys and the sum 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 : Number?> Grouped<T>.sum(name: String? = null, skipNaN: Boolean = skipNaNDefault, columns: ColumnsSelector<T, C>): DataFrame<T>

Aggregates this GroupBy by computing a single sum 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 sum per group. That column is named name, or, if name is null, after the selected column if exactly one column is selected, and "sum" otherwise.

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.

This can include column groups and nested columns.

See Selecting Columns.

See also:

  • sumFor — the sum of each selected column separately, per group.

  • sumOf — the sum of the values a row expression returns for each row of a 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 all values in the "age" and "weight" columns,
// in a column called "total"
df.groupBy { city }.sum("total") { age and weight }

Return

A new DataFrame with the group keys and a single sum 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 "sum" 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 sum of.


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

Aggregates this GroupBy by computing a single sum 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 sum per group. That column is named name, or, if name is null, after the selected column if exactly one column is selected, and "sum" otherwise.

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.

This can include column groups and nested columns.

See Selecting Columns.

See also:

  • sumFor — the sum of each selected column separately, per group.

  • sumOf — the sum of the values a row expression returns for each row of a 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 all values in the "age" and "weight" columns,
// in a column called "total"
df.groupBy { city }.sum("age", "weight", name = "total")

Return

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

Parameters

columns

The names of the columns to compute the sum of. These must be existing primitive number columns, else an IllegalStateException or IllegalArgumentException 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 "sum" 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>.sum(separate: Boolean = false, skipNaN: Boolean = skipNaNDefault): DataRow<T>

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

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

All columns of a primitive number type (and all "mixed" Number columns) 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 sum, flatten the DataFrame first.

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:

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

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

  • Pivot aggregation — all other ways to aggregate a Pivot.

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

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 each number column ("age" and "weight")
df.pivot { city }.sum()

Return

A single DataRow with the sum 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 : Number?> Pivot<T>.sum(skipNaN: Boolean = skipNaNDefault, columns: ColumnsSelector<T, C>): DataRow<T>

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

Returns a single DataRow with the pivot keys as (nested) columns, containing the sum of all the values in the selected columns of the corresponding group.

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.

This can include column groups and nested columns.

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 sum of all values in the "age" and "weight" columns
df.pivot { city }.sum { age and weight }

Return

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


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

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

Returns a single DataRow with the pivot keys as (nested) columns, containing the sum of all the values in the selected columns of the corresponding group.

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.

This can include column groups and nested columns.

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 sum of all values in the "age" and "weight" columns
df.pivot { city }.sum("age", "weight")

Return

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

Parameters

columns

The names of the columns to compute the sum of. These must be existing primitive number columns, else an IllegalStateException or IllegalArgumentException 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>.sum(separate: Boolean = false, skipNaN: Boolean = skipNaNDefault): DataFrame<T>

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

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

All columns of a primitive number type (and all "mixed" Number columns) 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 sum, flatten the DataFrame first.

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 each number column ("age" and "weight")
df.pivot { city }.groupBy { name.lastName }.sum()

Return

A DataFrame with the sum of each suitable column per 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 : Number?> PivotGroupBy<T>.sum(skipNaN: Boolean = skipNaNDefault, columns: ColumnsSelector<T, C>): DataFrame<T>

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

Returns a DataFrame where each cell contains the sum of all the values in the selected columns of the group corresponding to that pivot key (column) and groupBy key (row).

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.

This can include column groups and nested columns.

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 sum of all values in the "age" and "weight" columns
df.pivot { city }.groupBy { name.lastName }.sum { age and weight }

Return

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


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

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

Returns a DataFrame where each cell contains the sum of all the values in the selected columns of the group corresponding to that pivot key (column) and groupBy key (row).

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.

This can include column groups and nested columns.

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 sum of all values in the "age" and "weight" columns
df.pivot { city }.groupBy { name.lastName }.sum("age", "weight")

Return

A DataFrame with, per group, the sum of all the values in the selected columns.

Parameters

columns

The names of the columns to compute the sum of. These must be existing primitive number columns, else an IllegalStateException or IllegalArgumentException 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.


@JvmName(name = "sumShort")
fun <T, C : Short?> DataFrame<T>.sum(vararg columns: ColumnReference<C>): Int
@JvmName(name = "sumByte")
fun <T, C : Byte?> DataFrame<T>.sum(vararg columns: ColumnReference<C>): Int
@JvmName(name = "sumNumber")
fun <T, C : Number?> DataFrame<T>.sum(vararg columns: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): C & Any
@JvmName(name = "sumShort")
fun <T> DataFrame<T>.sum(vararg columns: KProperty<Short?>): Int
@JvmName(name = "sumByte")
fun <T> DataFrame<T>.sum(vararg columns: KProperty<Byte?>): Int
@JvmName(name = "sumNumber")
fun <T, C : Number?> DataFrame<T>.sum(skipNaN: Boolean = skipNaNDefault, vararg columns: KProperty<C>): C & Any
fun <T, C : Number?> Grouped<T>.sum(vararg columns: ColumnReference<C>, name: String? = null, skipNaN: Boolean = skipNaNDefault): DataFrame<T>
fun <T, C : Number?> Grouped<T>.sum(vararg columns: KProperty<C>, name: String? = null, skipNaN: Boolean = skipNaNDefault): DataFrame<T>
fun <T, C : Number?> Pivot<T>.sum(vararg columns: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): DataRow<T>
fun <T, C : Number?> Pivot<T>.sum(vararg columns: KProperty<C>, skipNaN: Boolean = skipNaNDefault): DataRow<T>
fun <T, C : Number?> PivotGroupBy<T>.sum(vararg columns: ColumnReference<C>, skipNaN: Boolean = skipNaNDefault): DataFrame<T>
fun <T, C : Number?> PivotGroupBy<T>.sum(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