View source: R/summarise_group_stats.R
summarise_group_stats | R Documentation |
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.
summarise_group_stats(
df,
group_var,
values,
m_functions = c("mean", "sd", "length"),
replace_na = FALSE,
remove_na = FALSE
)
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. |
A tibble with grouped and summarized results.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.