The “mean” Function in R
Package: Base R (no specific package required)
Purpose: Calculates the arithmetic mean of a numeric vector.
General Class: Descriptive Statistics
Required Argument(s):
x: A numeric vector.
Notable Optional Arguments:
trim: Fraction (0 to 0.5) of observations to be trimmed from each end of x before the mean is computed. The default is 0.
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 mean without trimming and including NA values
result <- mean(data, na.rm = TRUE)
print(result)In this example, the mean function is used to calculate the mean 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.