rank#
- swordfish.function.rank()#
Based on the sort order specified by ascending, this function returns the ranking (starting from 0) of each element in X.
If X is a vector, return a vector with the same length as X:
If groupNum is specified, divide the sorted vector X into groupNum groups and return the group number (starting from 0) for each element in X.
If the number of elements in X cannot be divided by groupNum, the first mod(size(X), groupNum) groups will hold one more element. For example, X has 6 elements, groupNum is specified as 4, the first and second elements of sorted vector X belong to group 0, the third and fourth elements belong to group 1, and the fifth and sixth elements belong to groups 2 and 3, respectively.
If the identical elements are not divided in the same group, return the smallest group number for all identical elements.
If ignoreNA = true, null values are ignored and return NULL.
If X is a matrix/table, conduct the aforementioned calculation within each column of X. The result is a matrix/table with the same shape as X.
If X is a dictionary, the ranking is based on its values, and the ranks of all elements are returned.
- Parameters:
X (Constant) – A vector/matrix/table/dictionary.
ascending (Constant, optional) – A Boolean value indicating whether the sorting is in ascending order. The default value is true (ascending).
groupNum (Constant, optional) – A positive integer indicating the number of groups to sort X into.
ignoreNA (Constant, optional) – A Boolean value indicating whether null values are ignored.
tiesMethod (Constant, optional) –
A string indicating how to rank the group of elements with the same value (i.e., ties):
’min’ : the smallest rank value of the tie values.
’max’ : the largest rank value of the tie values.
’average’ : the average of the rank values for all ties.
’first’: Gives the first found tie value the lowest rank value, and continues with the following rank value for the next tie.
percent (Constant, optional) – A Boolean value, indicating whether to display the returned rankings in percentile form. The default value is false.
precision (Constant, optional) – An integer between [1, 15]. If the absolute difference between two values is no greater than 10^(-precision), the two values are considered to be equal.