This function calculates summary statistics for a given numeric vector, including mean, standard deviation, quartiles, and missing value counts. The function supports both population and sample standard deviation calculations.
Value
A data frame with the following columns:
- mean
The mean of the non-missing values in
x
.- sd
The standard deviation of the non-missing values in
x
.- q25
The 25th percentile (first quartile).
- q50
The 50th percentile (median).
- q75
The 75th percentile (third quartile).
- n_val
The count of non-missing values.
- n_na
The count of missing values.
Examples
# Generate example data
set.seed(123)
data <- c(rnorm(100, mean = 50, sd = 10), NA, NA)
# Compute summary statistics
summary_stat(data)
#> mean sd min q25 q50 q75 max n_val n_na
#> 1 50.90406 9.128159 26.90831 45.06146 50.61756 56.91819 71.87333 100 2
summary_stat(data, descriptive = TRUE)
#> mean sd min q25 q50 q75 max n_val n_na
#> 1 50.90406 9.082403 26.90831 45.06146 50.61756 56.91819 71.87333 100 2