The “median” Function in R
Package: Base R (no specific package required)
Purpose: Calculates the median of a numeric vector.
General Class: Descriptive Statistics
Required Argument(s):
x: A numeric vector.
Notable Optional Arguments:
na.rm: A logical value indicating whether NA values should be stripped before the computation proceeds. The default is FALSE.
Example:
# Example vector
data <- c(2, 4, 6, 8, 10, NA)
# Calculate median excluding NA values
result <- median(data, na.rm = TRUE)
print(result)In this example, the median function calculates the median of the numeric vector data. The na.rm argument is set to TRUE to exclude NA values from the calculation. The result is then printed to the console.