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:
x1 < - c( 2 , 3 , 5 , 7 , 4 , 8 , 6 )
x2 < - c( - 3 , - 5 , 6 , 2 , - 4 )
median(x1)
median(x2)
|
Output:
[1] 5
[1] -3
Example 2:
x < - c( 2 , 3 , 5 , NA, 4 , NA, 6 )
median(x, na.rm = FALSE)
median(x, na.rm = TRUE)
|
Output:
[1] NA
[1] 4