Delta
Creates a Delta
UpdateByOperation
for the supplied column names. The Delta
operation produces values by computing the difference between the current value and the previous value. By default, null values in the current or previous cell produce null output. This behavior can be changed using DeltaControl
.
Syntax
Delta(pairs...)
Delta(control, pairs...)
Parameters
Parameter | Type | Description |
---|---|---|
pairs | String... | The input/output column name pairs. |
control | DeltaControl | Defines how special cases should behave. See |
Returns
An UpdateByOperation
to be used in an updateBy
table operation.
Examples
One column, no groups
The following example calculates the delta
of the X
column, renaming the resultant column to Delta_X
. No grouping columns are specified, so the delta
is calculated for all rows.
source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "X = randomInt(0,25)")
result = source.updateBy([Delta("Delta_X = X")])
- source
- result
One Delta column, one grouping column
The following example builds on the previous by specifying Letter
as the key column. Thus, the Delta is calculated on a per-letter basis.
source = emptyTable(10).update("Letter = (i % 2 == 0) ? `A` : `B`", "X = randomInt(0,25)")
result = source.updateBy([Delta("Delta_X = X")], "Letter")
- source
- result
Multiple Delta columns, multiple grouping columns
The following example builds on the previous by calculating the Delta of multiple columns with each UpdateByOperation
. Also, the groups are defined by unique combinations of letter and boolean in the Letter
and Truth
columns, respectively.
source = emptyTable(20).update("Letter = (i % 2 == 0) ? `A` : `B`", "Truth = randomBool()", "X = randomInt(0, 25)", "Y = randomInt(0, 25)")
result = source.updateBy([Delta("Delta_X = X", "Delta_Y = Y")], "Letter", "Truth")
- source
- result
Multiple UpdateByOperations
, multiple grouping columns
The following example builds on the previous by calculating Delta of the X and Y columns using different Delta
UpdateByoperations.
source = emptyTable(20).update("Letter = (i % 2 == 0) ? `A` : `B`", "Truth = randomBool()", "X = randomInt(0, 25)", "Y = randomInt(0, 25)")
DeltaX = Delta("DeltaX = X")
DeltaY = Delta("DeltaY = Y")
result = source.updateBy([DeltaX, DeltaY], "Letter", "Truth")
- source
- result