summarise_group_stats {tidySummaries} | R Documentation |
Summarize Grouped Statistics
Description
Groups a data frame by one or more variables and summarizes the selected numeric columns using basic statistic functions. Handles missing values by replacement with zero or removal of rows.
Usage
summarise_group_stats(
df,
group_var,
values,
m_functions = c("mean", "sd", "length"),
replace_na = FALSE,
remove_na = FALSE
)
Arguments
df |
A data frame or tibble containing the data. |
group_var |
A character vector of column names to group by. |
values |
A character vector of numeric column names to summarize. |
m_functions |
A character vector of functions to apply (e.g., "mean", "sd", "length"). Default is c("mean", "sd", "length"). |
replace_na |
Logical. If TRUE, missing values in numeric columns are replaced with 0. Default is FALSE. |
remove_na |
Logical. If TRUE, rows with missing values in group or value columns are removed. Default is FALSE. |
Value
A tibble with grouped and summarized results.
Examples
summarise_group_stats(iris, group_var = "Species",
values = c("Sepal.Length", "Petal.Width"))
summarise_group_stats(mtcars,
group_var = c("cyl", "gear"),
values = c("mpg", "hp"), remove_na = TRUE)
[Package tidySummaries version 0.1.0 Index]