View source: R/ct_describe_df.R
| ct_describe_df | R Documentation |
This function provides a summary of a dataset, including both numeric and
non-numeric variables. For numeric variables, it calculates basic descriptive
statistics such as minimum, maximum, median, mean, and count of non-missing
values. Additionally, users can pass custom functions via the fn argument to
compute additional statistics for numeric variables. For non-numeric variables,
it provides frequency counts and proportions for each unique value.
ct_describe_df(data, ..., fn = NULL, by_group = TRUE)
data |
A data frame containing the dataset to be summarized. |
... |
(Optional) Columns to include in the summary. If no column is specified, all columns in the data will be included. |
fn |
A list of functions to apply to numeric variables. Each function
must accept |
by_group |
Logical, default |
A tibble whose shape depends on by_group.
With by_group = TRUE (and at least one categorical and one numeric variable),
the data are grouped by the selected categorical variable(s) and each numeric
variable is summarised within every group. The result has one row per numeric
variable and group combination, with columns:
VariableName of the numeric variable being summarised.
One column per selected categorical variable, each holding the group value.
NNumber of non-missing values of Variable in the group.
Min, Max, Median, MeanDescriptive statistics of Variable
within the group.
CI Left, CI RightLower and upper bounds of the 95% t-based
confidence interval for the group mean (see ct_ci()).
With by_group = FALSE (also used as a fallback when only numeric or only
categorical variables are selected), numeric and categorical summaries are
stacked into one tibble with one row per numeric variable and one row per
distinct value of each categorical variable; columns that do not apply to a row
are NA:
VariableName of the summarised column.
GroupFor a categorical variable, the distinct value described;
NA for numeric variables.
PropFor a categorical variable, the percentage of its non-missing
records falling in Group; NA for numeric variables.
NNon-missing count: values for a numeric variable, or records in
Group for a categorical variable.
Min, Max, Median, MeanNumeric statistics; NA for
categorical variables.
CI Left, CI Right95% t-based confidence interval bounds for the
mean (see ct_ci()); NA for categorical variables.
In both modes, supplying fn appends one extra column per named function,
holding that statistic for each numeric variable (or group).
parse_list_fn
df <- data.frame(x = c(1:3, NA),
y = c(3:4, NA, NA),
z = c("A", "A", "B", "A"))
# Numeric variables summarised within each group of the categorical variable
ct_describe_df(df, y, x, z)
# Summarise every variable independently
ct_describe_df(df, y, x, z, by_group = FALSE)
# Add custom statistics for the numeric variables
ct_describe_df(df, y, x, z,
fn = list('sum' = list(na.rm = TRUE), 'sd' = list(na.rm = TRUE)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.