Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
Calculate the Mean of each Row of an Object in R Programming – rowMeans() Function
Next article icon

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

Last Updated : 15 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

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:




# 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  


Next Article
Calculate the Mean of each Row of an Object in R Programming – rowMeans() Function

N

nidhi_biet
Improve
Article Tags :
  • R Language
  • R Vector-Function

Similar Reads

  • Calculate Trace of a Matrix in R Programming - tr() Function
    tr() function in R Language is used to calculate the trace of a matrix. Trace of a matrix is the sum of the values on the main diagonal(upper left to lower right) of the matrix. Syntax: tr(x) Parameters: x: Matrix Example 1: # R program to calculate # trace of a matrix # Loading library library(psyc
    1 min read
  • Calculate the Cumulative Maxima of a Vector in R Programming - cummax() Function
    The cumulative maxima is the max value of elements 1 through l for an element l of the given variables. cummax() function in R Language is used to calculate the cumulative maxima of the values of vector passed as arguments. Syntax: cummax(x)  Parameters:  x: numeric object Example 1:  [GFGTABS] Pyth
    2 min read
  • Calculate the Cumulative Minima of a Vector in R Programming - cummin() Function
    cummin() function in R Language is used to calculate the cumulative minima of the values of vector passed as arguments. Syntax: cummin(x) Parameters: x: numeric object Example 1: # R program to cumulative minima # Calling cummin() function cummin(2:6) cummin(-2:-6) cummin(1.8:4.2) Output: [1] 2 2 2
    1 min read
  • Calculate the Mean of each Row of an Object in R Programming – rowMeans() Function
    rowMeans() function in R Language is used to find out the mean of each row of a data frame, matrix, or array. Syntax: rowMeans(data) Parameter: data: data frame, array, or matrix Example 1 # R program to illustrate # rowMean function # Create example values # Set seed set.seed(1234) # Create example
    1 min read
  • Sorting of a Vector in R Programming - sort() Function
    In R Programming Language we can sort a vector in ascending or descending order using the sort() function. The sort() function returns a sorted version of the input vector. sort() function in is used to sort a vector by its values. It takes the Boolean value as an argument to sort in ascending or de
    2 min read
  • Calculate Median of elements of a Vector in R Programming - median() Function
    median() function in R Language is used to calculate the median of the elements of the numeric vector passed as argument. Syntax: median(x, na.rm) Parameters: x: Numeric Vector na.rm: Boolean value to ignore NA Example 1: # R program to calculate median of a vector # Creating vector x1 <- c(2, 3,
    1 min read
  • Convert values of an Object to Logical Vector in R Programming - as.logical() Function
    as.logical() function in R Language is used to convert an object to a logical vector. Syntax: as.logical(x)Parameters: x: Numeric or character object R - as.logical() Function ExampleExample 1: Basic example of as.logical() Function in R Programming Language.[GFGTABS] R # R Program to convert # an o
    1 min read
  • Calculate nCr value in R Programming - choose() Function
    R Language offers a direct function that can compute the nCr value without writing the whole code for computing nCr value. Syntax: choose(n, r) Parameters: n: Number of elements r: Number of combinations Returns: The number of r combinations from a total of n elements, i.e, nCr value. Example 1: # R
    1 min read
  • Get the Minimum and Maximum element of a Vector in R Programming - range() Function
    range() function in R Programming Language is used to get the minimum and maximum values of the vector passed to it as an argument. Syntax: range(x, na.rm, finite) Parameters:  x: Numeric Vectorna.rm: Boolean value to remove NAfinite: Boolean value to exclude non-finite elementsR - range() Function
    1 min read
  • Creating a Vector of sequenced elements in R Programming - seq() Function
    In This article, we will discuss how we Create a Vector of sequenced elements in R Programming Language using seq() Function. What are sequenced elements?Sequenced elements mean things that are placed in a particular order, one after another. This concept is often used in various fields. seq() Funct
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences