cuminv
cuminv, function
def process cuminv(a: number): zedfunc
Returns a zedfunc that maps cumulative sums of a back to positions along the
specified sort order.
a: non-negative values to accumulate.
Examples
table Buckets = with
[| as Step, as Qty |]
[| 1, 2 |]
[| 2, 1 |]
[| 3, 3 |]
z = cuminv(Buckets.Qty) sort Buckets.Step
table X = with
[| as CumQty |]
[| 1 |]
[| 2 |]
[| 3 |]
[| 4 |]
[| 5 |]
[| 6 |]
X.Step = valueAt(z, X.CumQty)
show table "Inverse" with
X.CumQty
X.Step
This produces the following table:
| CumQty | Step |
|---|---|
| 1 | 1 |
| 2 | 1 |
| 3 | 2 |
| 4 | 3 |
| 5 | 3 |
| 6 | 3 |
Remarks
cuminv requires a sort order. Use by to compute independent zedfuncs per
group.
The returned zedfunc can be queried with valueAt. For a cumulative sum s,
valueAt(z, s) returns the first position where the cumulative sum reaches
s or more.
Errors
cuminv expects non-negative values. A negative value triggers a fatal error:
‘cuminv()’ expects non-negative values. Found -20 at index 3