def nosort process sum(a: number): number
def nosort process sum(a: embedding): embedding
def nosort process sum(a: ranvar): ranvar
def nosort process sum(a: zedfunc): zedfunc
Returns the sum of a within each group.
Example
table T = with
[| as A, as B |]
[| 0, "a" |]
[| 0.5, "a" |]
[| 0, "b" |]
[| 1, "b" |]
[| 1, "c" |]
table G[gdim] = by T.B
show table "Sum by group" with
gdim
sum(T.A) as "Total"
group by gdim
This outputs the following table:
gdim
Total
a
0.5
b
1
c
1
Remarks
For embedding inputs, the output is the coordinate-wise sum of the embeddings.
The embedding overload uses embzero() as its default embedding value.
For ranvar and zedfunc inputs, the output is the sum of distributions or
functions, respectively. Empty groups return 0, embzero(), dirac(0), or
constant(0) depending on the input type.