# cumrank

Syntax

cumrank(X, [ascending=true], [ignoreNA=true], [tiesMethod=’min’], [percent=false)

Please see Cumulative Window Functions (cum-functions) for the parameters and windowing logic.

Arguments

X is a vector/ matrix.

ascending is a Boolean value indicating whether to sort in ascending order. It is an optional parameter and the default value is true.

ignoreNA is a Boolean value indicating whether Null values are ignored in ranking. True means ignoring the Null value, and false means the Null values participate in the calculation. The default value is true. If Null values participate in the ranking, they are ranked the lowest.

tiesMethod is a string indicating how to rank the group of records with the same value (i.e., ties):

• ‘min’: lowest rank of the group

• ‘max’: highest rank of the group

• ‘average’: average rank of the group

percent 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, for each element in X, return the position ranking from the first element to the current element. The result is of the same length as X. If ignoreNA = true, NULL values 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.

Examples

```\$ cumrank(1 3 2 3 4);
[0,1,1,2,4]

\$ cumrank(1 3 2 2 4 NULL, , true);
[0,1,1,1,4,]

\$ cumrank(1 3 2 2 4 NULL, , false);
[0,1,1,1,4,0]

\$ cumrank(1 3 2 2 4 NULL, , false, 'max');
[0,1,1,2,4,0]

\$ m=matrix(1 4 2 3 4, 4 NULL 6 1 2);
\$ m;
```

#0

#1

1

4

4

2

6

3

1

4

2

```\$ cumrank(m);
```

#0

#1

0

0

1

1

1

2

0

3

1

Related function: rank