rankd

rankd, function

def process rankd(a: number): number

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

Example

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
User Contributed Notes
0 notes + add a note