# 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``, ``5``, ``7``, ``4``, ``8``, ``6``) ` `x2 <``-` `c(``-``3``, ``-``5``, ``6``, ``2``, ``-``4``) ` ` `  `# Calling median() function ` `median(x1) ` `median(x2) `

Output:

``` 5
 -3
```

Example 2:

 `# 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:

``` NA
 4
```
My Personal Notes arrow_drop_up Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.