avg

avg, function

def autodiff process avg(a: number): number

Returns the numerical average of the grouped numbers in a. For empty groups, it returns 0.

Examples

table T = with
  [| as A, as B |]
  [| 0,   "a"   |]
  [| 0,   "a"   |]
  [| 0,   "b"   |]
  [| 1,   "b"   |]
  [| 1,   "c"   |]

table G[gdim] = by T.B

show table "Average by group" with
  gdim
  avg(T.A)
  group by gdim

Output:

gdim avg(T.A)
a 0
b 0.5
c 1

Remarks

This function is usable in autodiff contexts.

See also

User Contributed Notes
0 notes + add a note