repl.txt (2181B)
1 2 {{alias}}( arr[, options] ) 3 Computes the sample ranks for the values of an array-like object. 4 5 When all elements of the `array` are different, the ranks are uniquely 6 determined. When there are equal elements (called *ties*), the `method` 7 option determines how they are handled. The default, `'average'`, replaces 8 the ranks of the ties by their mean. Other possible options are `'min'` and 9 `'max'`, which replace the ranks of the ties by their minimum and maximum, 10 respectively. `'dense'` works like `'min'`, with the difference that the 11 next highest element after a tie is assigned the next smallest integer. 12 Finally, `ordinal` gives each element in `arr` a distinct rank, according to 13 the position they appear in. 14 15 The `missing` option is used to specify how to handle missing data. 16 By default, `NaN` or `null` are treated as missing values. `'last'`specifies 17 that missing values are placed last, `'first'` that the are assigned the 18 lowest ranks and `'remove'` means that they are removed from the array 19 before the ranks are calculated. 20 21 Parameters 22 ---------- 23 arr: Array<number> 24 Input values. 25 26 options: Object (optional) 27 Function options. 28 29 options.method (optional) 30 Method name determining how ties are treated (`average`, `min`, `max`, 31 `dense`, or `ordinal`). Default: `'average'`. 32 33 options.missing (optional) 34 Determines where missing values go (`first`, `last`, or `remove`). 35 Default: `'last'`. 36 37 options.encoding (optional) 38 Array of values encoding missing values. Default: `[ null, NaN ]`. 39 40 Returns 41 ------- 42 out: Array 43 Array containing the computed ranks for the elements of the input array. 44 45 Examples 46 -------- 47 > var arr = [ 1.1, 2.0, 3.5, 0.0, 2.4 ] ; 48 > var out = {{alias}}( arr ) 49 [ 2, 3, 5, 1, 4 ] 50 51 // Ties are averaged: 52 > arr = [ 2, 2, 1, 4, 3 ]; 53 > out = {{alias}}( arr ) 54 [ 2.5, 2.5, 1, 5, 4 ] 55 56 // Missing values are placed last: 57 > arr = [ null, 2, 2, 1, 4, 3, NaN, NaN ]; 58 > out = {{alias}}( arr ) 59 [ 6, 2.5, 2.5, 1, 5, 4, 7 ,8 ] 60 61 See Also 62 -------- 63