The “sd” Function in R
Package: Base R (no specific package required)
Purpose: Calculates the standard deviation 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 standard deviation excluding NA values
result <- sd(data, na.rm = TRUE)
print(result)In this example, the sd function is used to calculate the standard deviation 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.