CumProd
CumProd
calculates a cumulative product in an updateBy
table operation.
Syntax
CumProd(pairs...)
Parameters
Parameter | Type | Description |
---|---|---|
pairs | String... | The column(s) to be operated on. These can include expressions to rename the output columns (e.g., |
Returns
An UpdateByOperation
to be used in an updateBy
table operation.
Examples
The following example performs an updateBy
on the source
table using the CumProd
operation. No grouping columns are given, so the cumulative product is calculated across all rows of the table.
source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "X = i + 1")
result = source.updateBy(CumProd("ProdX = X"))
- source
- result
The following example builds on the previous by specifying Letter
as a grouping column. Thus, the cumulative product in the result
table is calculated on a per-letter basis.
source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "X = i + 1")
result = source.updateBy(CumProd("ProdX = X"), "Letter")
- source
- result
The following example builds on the previous by calculating the cumulative product of two columns using the same UpdateByOperation
.
source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "X = i + 1", "Y = randomInt(1, 7)")
result = source.updateBy(CumProd("ProdX = X", "ProdY = Y"), "Letter")
- source
- result
The following example builds on the previous by specifying two grouping columns: Letter
and Truth
. Thus, groups consist of unique combinations of letter in Letter
and boolean in Truth
.
source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "Truth = randomBool()", "X = i + 1", "Y = randomInt(1, 7)")
result = source.updateBy(CumProd("ProdX = X", "ProdY = Y"), "Letter", "Truth")
- source
- result