bdVector
of the ranks of the input.
rank(x, na.last = T)
bdNumeric
.
Missing values (NA) are allowed.
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
.
i
th value is the rank of
x[i]
. In
case of ties, the average rank is returned.
The treatment of missing values is controlled by
na.last
.
For the rank of a matrix see
svd
,
qr
or
chol
.
If
na.last=NA
, the
i
th value of the result corresponds to the
i
th
element of the vector that is the result of removing
NA
s from
x
.
# 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