rank(x [ ,down:T, ties:"ignore" or "average" or "minimum"]), x REAL or CHARACTER or a structure with all REAL or all CHARACTER components. |

rank(x) computes the ranks of the data in variable x, the minimum value being assigned rank 1. In case of ties, the rank corresponding to the average of the ranks for the tied cases is computed. x can be REAL or CHARACTER. When x is CHARACTER, x[i] is considered greater than x[j] if x[i] follows x[j] in alphabetical order using the ASCII collating sequence. See sort() for the explicit ordering of characters. rank(x,down:T) does the same except that the data are ranked in decreasing order, with rank 1 assigned to the maximum element. rank(x,ties:Method) or rank(x,ties:Method,down:T), where Method is one of "average", "minimum" or "ignore" (or simply "a", "m" or "i"), treats ties as described below. With REAL x, rank(x,ties:"average" [,down:T]) gives the same ranks as rank(x [,down:T]). When x is CHARACTER, keyword 'ties' is ignored and is assumed to have value "i". rank(x [keywords]) has the same labels as x, if any. When x is a matrix, the result is a matrix each of whose columns contains the ranks of the elements of the corresponding column of x. When x is an array with dimensions n1, n2, ..., the result is an array of the same size and shape with all the elements with fixed values of subscripts 2, 3, ... defining a "column" whose ranks are computed. An array with dimension > 2 is always treated as an array and not as a matrix, even if there are at most two dimensions greater than 1. It is also acceptable for x to be a structure, whose non-structure components are all REAL or all CHARACTER. In that case, rank() returns a structure of the same form, each of whose non-structure components is the result of applying rank() to the corresponding component of x. When x is REAL and there are MISSING values in a column, their rank is also MISSING and the maximum rank of the non-missing values is the number of non-missing values. Treatment of Ties with REAL Data Suppose k elements in a vector (column) are tied, that is they all have the same value and no other element has this value, and suppose the ranks these elements would have if their values were very slightly changed so as to break the ties while preserving other ordering would be r, r+1, r+2, ..., r+k-1. The following describes the ranks computed for the tied values for each of the three possible methods. Value for 'ties' Computed ranks "average" or "a" (default) All ranks = (r+(r+1)+...+(r+k-1))/k = r+(k-1)/2 "minimum" or "m" All ranks = r "ignore" or "i" r, r+1, r+2, ..., r+k-1; which ranks go in which position is unpredictable Examples: Cmd> x <- vector(27,22,25,26,22,21,?,24) # 1 tie, 1 MISSING Cmd> rank(x) # or rank(x,ties:"a") WARNING: MISSING values in argument to rank (1) 7 2.5 5 6 2.5 (6) 1 MISSING 4 Cmd> rank(x,down:T) (1) 1 5.5 3 2 5.5 (6) 7 MISSING 4 Cmd> rank(x,ties:"m") (1) 7 2 5 6 2 (6) 1 MISSING 4 Cmd> rank(x,ties:"m",down:T) (1) 1 5 3 2 5 (6) 7 MISSING 4 Cmd> rank(x,ties:"i") (1) 7 2 5 6 3 (6) 1 MISSING 4 In each example except the first, a warning message about MISSING values has been deleted. See also grade(), sort().

Gary Oehlert 2003-01-15