View source: R/create_summary_statistics.R
| create_summary_statistics | R Documentation |
Computes a set of summary statistics for numeric and integer variables in a
data frame. It allows users to select specific variables for
summarization and can calculate statistics for the whole dataset or within
groups specified by the by argument. Additional detail levels for quantiles
can be included.
create_summary_statistics(
data,
...,
by = NULL,
detail = FALSE,
drop_na = FALSE
)
data |
A data frame containing the variables to be summarized. |
... |
Comma-separated list of unquoted variable names in the data frame to summarize. These variables must be either numeric, integer, or logical. |
by |
An optional unquoted variable name to group the data before
summarizing. If |
detail |
A logical flag indicating whether to compute detailed summary
statistics, including additional quantiles. Defaults to |
drop_na |
A logical flag indicating whether to drop missing values for
each variable (default is |
The function first checks that all specified variables are of type numeric, integer, or logical. If any variables do not meet this criterion, the function stops and returns an error message indicating the non-conforming variables.
The basic set of summary statistics includes the count of non-NA values (n),
mean, standard deviation (sd), minimum (min), median (q50), and maximum
(max). If detail is TRUE, the function also computes the 1st, 5th, 10th,
25th, 75th, 90th, 95th, and 99th percentiles.
Summary statistics are computed for each variable specified in .... If a
by variable is provided, statistics are computed within each level of the
by variable.
A tibble with summary statistics for each selected variable. If by
is specified, the output includes the grouping variable as well. Each row
represents a variable (and a group if by is used), and each column
contains the computed statistics.
Other utility functions:
get_available_huggingface_files(),
list_supported_datasets(),
list_supported_datasets_ff(),
list_supported_datasets_ff_legacy(),
list_supported_datasets_macro_predictors(),
list_supported_datasets_other(),
list_supported_datasets_pseudo(),
list_supported_datasets_wrds(),
list_supported_indexes(),
list_tidy_finance_chapters(),
open_tidy_finance_website(),
trim(),
validate_dates(),
winsorize()
data <- data.frame(
ret = c(0.01, -0.02, 0.03, NA, 0.005),
size = c(100, 200, 150, 300, 250),
group = c("A", "A", "B", "B", "A")
)
# Basic summary across all observations
create_summary_statistics(data, ret, size)
# Grouped summary
create_summary_statistics(data, ret, size, by = group)
# Detailed quantiles
create_summary_statistics(data, ret, detail = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.