rankd

rankd, function

def call rankd(a: sortable, groups: by grouping): number

Returns ranks within each group in decreasing order, starting at 1. Ties receive the same rank.

Examples

table T = with
  [| as N, as G |]
  [| 5, "a" |]
  [| 5, "a" |]
  [| 1, "a" |]
  [| 2, "b" |]
  [| 2, "b" |]
  [| 1, "b" |]

T.Rk = rankd(T.N) by T.G

show table "Ranks by group" with
  T.G
  T.N
  T.Rk

This outputs the following table:

G N Rk
a 5 1
a 5 1
a 1 2
b 2 1
b 2 1
b 1 2

Text scores are supported as well:

table T = with
  [| as Label |]
  [| "B" |]
  [| "A" |]
  [| "B" |]
  [| "C" |]

T.Rank = rankd(T.Label)
show table "Text ranks" with T.Label, T.Rank

The ranks are 2, 3, 2, and 1, respectively.

Remarks

Scores can be number, boolean, text, date, week, month, an enum, ordinal, i64, or f64. A flagset can be a grouping key but cannot be a score. See by for grouping keys.

See also

User Contributed Notes
0 notes + add a note