Calculate Rank of the Values of a Vector in R Programming – rank() Function

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.**rank()**

Syntax:rank(x, na.last)

Parameters:x:numeric, complex, character, and logical vectorna.last:Boolean Value to remove NAs

**Example 1:**

`# R program to print rank of a vector values` ` ` `# Creating a vector` `x <` `-` `c(` `2` `, ` `5` `, ` `3` `, ` `6` `, ` `-` `4` `, NA, ` `7` `, Inf, ` `5` `)` ` ` `# Calling rank() function` `rank(x)` |

**Output:**

[1] 2.0 4.5 3.0 6.0 1.0 9.0 7.0 8.0 4.5

**Example 2:**

`# R program to print rank of a vector values` ` ` `# Creating a vector` `x <` `-` `c(` `2` `, ` `5` `, ` `3` `, ` `6` `, ` `-` `4` `, NA, ` `7` `, Inf, ` `5` `)` ` ` `# Calling rank() function` `rank(x)` ` ` `# Calling with NA removed` `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