denseRank

Syntax

denseRank(X, [ascending=true],[ignoreNA=true], [percent=false])

Arguments

X is a vector/matrix.

ascending (optional) is a Boolean value indicating whether to sort in ascending order. The default value is true.

ignoreNA (optional) is a Boolean value indicating whether NULL values are ignored in ranking. The default value is true. If set to false, NULL is ranked as the minimum value.

percent (optional) is a Boolean value, indicating whether to display the returned rankings in percentile form. The default value is false.

Details

If X is a vector:

  • return the consecutive rank of each element in X based on the specified ascending order.

  • If ignoreNA = true, the NULL values are ignored in ranking and return NULL.

If X is a matrix, conduct the aforementioned calculation within each column of X. The result is a matrix with the same shape as X.

Unlike denseRank, rank skips positions after equal rankings.

Examples

x=1 5 5 6 8 8 9
print denseRank(x)
// output
[0,1,1,2,3,3,4]

y=time(4 1 1 2)
print denseRank(y, ascending=false)
// output
[0,2,2,1]
m = matrix(1 2 2 NULL, 0 0 0 1, 0 0 NULL 2)
denseRank(m, ignoreNA=false)
#0 #1 #2
1 0 1
2 0 1
2 0 0
0 1 2
t=table(`A`A`B`C`B`B`A`C`C as id,[4,1,NULL,1,2,4,5,0,-1] as val)
select id,val, denseRank(val) from t context by id
id val denseRank_val
A 4 1
A 1 0
A 5 2
B
B 2 0
B 4 1
C 1 2
C 0 1
C -1 0

Related function: rowDenseRank