ratio

ratio, function

def nosort process ratio(a: boolean): number
def nosort process ratio(a: number): number
def nosort process ratio(a: text): number

Returns the fraction of values in a that are true, non-zero, or non-empty depending on the input type.

Examples

table T = with
  [| as A, as G |]
  [| false, "a" |]
  [| true,  "a" |]
  [| false, "b" |]
  [| true,  "b" |]
  [| true,  "c" |]

table G[gdim] = by T.G

show table "Ratio of true values" with
  gdim
  ratio(T.A) as "Ratio"
  group by gdim

This outputs the following table:

gdim Ratio
a 0.5
b 0.5
c 1
table U = with
  [| as A, as G |]
  [| "",    "a" |]
  [| "foo", "a" |]
  [| "",    "b" |]
  [| "foo", "b" |]
  [| "foo", "c" |]

table G[gdim] = by U.G

show table "Ratio of non-empty values" with
  gdim
  ratio(U.A) as "Ratio"
  group by gdim

This outputs the following table:

gdim Ratio
a 0.5
b 0.5
c 1

Remarks

The aggregator returns 1 on empty groups.

User Contributed Notes
0 notes + add a note