View source: R/summarize_group_cols.R
summarize_group_cols | R Documentation |
Get the following summary statistics for each group column:
Number of groups
Mean, median, std., IQR, min, and max number of rows per group.
The output can be given in either long (default) or wide format.
summarize_group_cols(data, group_cols, long = TRUE)
data |
|
group_cols |
Names of columns to summarize. These columns must be factors in |
long |
Whether the output should be in long or wide format. |
Data frame (tibble
) with summary statistics for each column in `group_cols`
.
Ludvig Renbo Olsen, r-pkgs@ludvigolsen.dk
Other summarization functions:
ranked_balances()
,
summarize_balances()
# Attach packages
library(groupdata2)
# Create data frame
df <- data.frame(
"some_var" = runif(25),
"grp_1" = factor(sample(1:5, size = 25, replace=TRUE)),
"grp_2" = factor(sample(1:8, size = 25, replace=TRUE)),
"grp_3" = factor(sample(LETTERS[1:3], size = 25, replace=TRUE)),
"grp_4" = factor(sample(LETTERS[1:12], size = 25, replace=TRUE))
)
# Summarize the group columns (long format)
summarize_group_cols(
data = df,
group_cols = paste0("grp_", 1:4),
long = TRUE
)
# Summarize the group columns (wide format)
summarize_group_cols(
data = df,
group_cols = paste0("grp_", 1:4),
long = FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.