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 Arithmetic mean in R Programming - mean() Function
Next article icon

Calculate Median of elements of a Vector in R Programming - median() Function

Last Updated : 05 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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: Python3 1==
# R program to calculate median of a vector  # Creating vector x1 <- c(2, 3, 5, 7, 4, 8, 6) x2 <- c(-3, -5, 6, 2, -4)  # Calling median() function median(x1) median(x2) 
Output:
  [1] 5  [1] -3  
Example 2: Python3 1==
# R program to calculate median of a vector  # Creating vector x <- c(2, 3, 5, NA, 4, NA, 6)  # Calling median() function # with NA values included median(x, na.rm = FALSE)  # Calling median() function # with NA values excluded median(x, na.rm = TRUE) 
Output:
  [1] NA  [1] 4  

Next Article
Calculate Arithmetic mean in R Programming - mean() Function

N

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

Similar Reads

  • Getting Match of an Element within a Vector in R Programming - charmatch() Function
    charmatch() function in R Programming Language is used to find matches between two arguments. Syntax: charmatch(x, table, nomatch = NA_integer_) Parameters:  x: the values to be matchedtable: the values to be matched againstnomatch: the integer value to be returned at non-matching positionr - charma
    1 min read
  • Calculate the Median Absolute Deviation in R Programming - mad() Function
    The Median Absolute Deviation is calculated in R Language using the mad() function. It is a statistical measurement of a dataset's dispersion or variability. Because it is resistant to outliers and extreme values, the MAD can serve as a robust alternative to standard deviation. The Median Absolute D
    2 min read
  • Calculate Arithmetic mean in R Programming - mean() Function
    mean() function in R Language is used to calculate the arithmetic mean of the elements of the numeric vector passed to it as argument. Syntax: mean(x, na.rm) Parameters: x: Numeric Vector na.rm: Boolean value to ignore NA value Example 1: # R program to calculate # Arithmetic mean of a vector # Crea
    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
  • Calculate the Mean of each Column of a Matrix or Array in R Programming - colMeans() Function
    colMeans() function in R Language is used to compute the mean of each column of a matrix or array. Syntax: colMeans(x, dims = 1) Parameters: x: array of two or more dimensions, containing numeric, complex, integer or logical values, or a numeric data frame dims: integer value, which dimensions are r
    2 min read
  • Get the Minimum element of an Object in R Programming - min() Function
    min() function in R Language is used to find the minimum element present in an object. This object can be a Vector, a list, a matrix, a data frame, etc.. Syntax: min(object, na.rm) Parameters: object: Vector, matrix, list, data frame, etc. na.rm: Boolean value to remove NA element. Example 1: # R pr
    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
  • Calculate the Sum of Matrix or Array columns in R Programming - colSums() Function
    colSums() function in R Language is used to compute the sums of matrix or array columns. Syntax: colSums (x, na.rm = FALSE, dims = 1) Parameters: x: matrix or array dims: this is integer value whose dimensions are regarded as ‘columns’ to sum over. It is over dimensions 1:dims. Example 1: # R progra
    2 min read
  • Calculate Rank of the Values of a Vector in R Programming - rank() Function
    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 progra
    1 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