View source: R/get_summary_stats.R
| get_summary_stats | R Documentation |
Compute summary statistics for one or multiple numeric variables.
See the Datanovia tutorial Descriptive Statistics in R for a worked walkthrough.
get_summary_stats(
data,
...,
type = c("full", "common", "robust", "five_number", "mean_sd", "mean_se", "mean_ci",
"median_iqr", "median_mad", "quantile", "mean", "median", "min", "max"),
show = NULL,
probs = seq(0, 1, 0.25),
digits = 3
)
data |
a data frame |
... |
(optional) One or more unquoted expressions (or variable names) separated by commas. Used to select a variable of interest. If no variable is specified, then the summary statistics of all numeric variables in the data frame is computed. |
type |
type of summary statistics. Possible values include: |
show |
a character vector specifying the summary statistics you want to
show. Example: |
probs |
numeric vector of probabilities with values in [0,1]. Used only when type = "quantile". |
digits |
integer indicating the number of decimal places to round the summary statistics to. Default is 3. Increase it when summarizing very small values that would otherwise round to 0. |
A data frame containing descriptive statistics, such as:
n: the number of individuals
min: minimum
max: maximum
median: median
mean: mean
q1, q3: the first and the third quartile, respectively.
iqr: interquartile range
mad: median absolute deviation (see ?MAD)
sd: standard deviation of the mean
se: standard error of the mean
ci: 95 percent confidence interval of the mean
When requested through show, the output can also contain:
skewness: bias-corrected sample skewness
kurtosis: bias-corrected sample excess kurtosis (0 for a normal distribution).
Both use the type-2 (bias-corrected) estimator, matching
e1071 with type = 2:
skewness = g_1\sqrt{n(n-1)}/(n-2) and kurtosis = [(n+1)g_2 + 6]
(n-1)/[(n-2)(n-3)], where g_1 = m_3/m_2^{1.5} and g_2 =
m_4/m_2^2 - 3. Skewness is NA for n < 3 and kurtosis for n < 4.
rstatix-programming for selecting columns by names held
in strings (!!, {{ }}, vars=, all_of()).
The Datanovia tutorial: Descriptive Statistics in R.
# Full summary statistics
data("ToothGrowth")
ToothGrowth %>% get_summary_stats(len)
# Summary statistics of grouped data
# Show only common summary
ToothGrowth %>%
group_by(dose, supp) %>%
get_summary_stats(len, type = "common")
# Robust summary statistics
ToothGrowth %>% get_summary_stats(len, type = "robust")
# Five number summary statistics
ToothGrowth %>% get_summary_stats(len, type = "five_number")
# Compute only mean and sd
ToothGrowth %>% get_summary_stats(len, type = "mean_sd")
# Compute full summary statistics but show only mean, sd, median, iqr
ToothGrowth %>%
get_summary_stats(len, show = c("mean", "sd", "median", "iqr"))
# Include skewness and kurtosis (computed on demand via show)
ToothGrowth %>%
get_summary_stats(len, show = c("mean", "sd", "skewness", "kurtosis"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.