rowSum

fun DataRow<*>.rowSum(skipNaN: Boolean = skipNaNDefault): Number

Returns the sum of all the numbers in this DataRow.

Only the values in the columns of a primitive number type (and in "mixed" Number columns) are taken into account; all other columns of the row are ignored.

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

Since the values of different columns are summed together, the result is the sum of all those values converted to their common type.

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:

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

Example

// The sum of all numbers ("age" and "weight") in the first row
// Columns of other types ("name" and "address") are ignored
df[0].rowSum()

Return

The sum of all the numbers in this row.

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.