rank()
function in R Language is used to return the sample ranks of the values of a vector. Equal values and missing values are handled in multiple ways.
Syntax: rank(x, na.last)
Parameters:
x: numeric, complex, character, and logical vector
na.last: Boolean Value to remove NAs
Example 1:
x < - c( 2 , 5 , 3 , 6 , - 4 , NA, 7 , Inf, 5 )
rank(x)
|
Output:
[1] 2.0 4.5 3.0 6.0 1.0 9.0 7.0 8.0 4.5
Example 2:
x < - c( 2 , 5 , 3 , 6 , - 4 , NA, 7 , Inf, 5 )
rank(x)
rank(x, na.last = FALSE)
|
Output:
[1] 2.0 4.5 3.0 6.0 1.0 9.0 7.0 8.0 4.5
[1] 3.0 5.5 4.0 7.0 2.0 1.0 8.0 9.0 5.5