Ranks of Data

DESCRIPTION:

Returns a vector or bdVector of the ranks of the input.

USAGE:

rank(x, na.last = T) 

REQUIRED ARGUMENTS:

x
numeric vector or bdNumeric . Missing values (NA) are allowed.

OPTIONAL ARGUMENTS:

na.last
vector or bdVector with one element. If na.last=TRUE, missing values are put last; if FALSE, they are put first. If na.last=NA, missing values are deleted. An error is given if na.last is of mode "character" or "bdCharacter" and missing values occur in x.

VALUE:

the ranks; i.e., the ith value is the rank of x[i]. In case of ties, the average rank is returned.

DETAILS:

The treatment of missing values is controlled by na.last.

For the rank of a matrix see svd, qr or chol.

WARNING:

If na.last=NA, the ith value of the result corresponds to the ith element of the vector that is the result of removing NAs from x.

SEE ALSO:

, , , , .

EXAMPLES:

# Create sample objects:
diffgeom <- testscores[,1] 
complexanal <- testscores[,2] 

rank(diffgeom, na.last="") # causes error if missing values are present 

# Spearman's rank correlation between two sets of testscores:
cor(rank(diffgeom), rank(complexanal)) 

# Create sample objects with missing values:
a <- c(4, 2, 5, 1, 4, NA, 6) 
b <- c(4, 2, 5, NA, 4, 5, 6)

# This does not correctly compute the Spearman's rank correlation of the
#   non-missing data:
cor(rank(a), rank(b))
# [1] 0.1651446

# This does compute the Spearman's rank correlation of non-missing data:
cor(rank(a[!is.na(a*b)]),rank(b[!is.na(a*b)])) # 
# [1] 1