View source: R/table_grouped_summary.R
table_grouped_summary | R Documentation |
Grouped Summary Table with optional html output
table_grouped_summary(
df,
var_names,
grouping_variable,
html_output = FALSE,
total = TRUE
)
df |
a dataframe |
var_names |
a character vector containing bare variable names |
grouping_variable |
a character string containing the grouping variable name |
html_output |
should the result be returned as an htmlTable (if 'html_tableā = TRUE) or as a dataframe (default) |
total |
should an overal total column be included (default) or omitted |
A text table with grouped summary
sprintf
, mean
, sd
, htmlTable
library(tidyverse)
by = list(cyl = mtcars[, "cyl"]),
FUN = function(x) sprintf("%.2f &pm %.2f", mean(x), sd(x))) %>%
t() %>%
as.data.frame() %>%
rownames_to_column() %>%
{names(.) <- unlist(.[1, ]); .} %>%
.[-1, ]
# output HTML format
mtcars %>%
table_grouped_summary(.,
var_names = c("disp", "hp", "drat", "mpg", "wt"),
grouping_variable = "cyl",
html_output = TRUE,
total = TRUE)
# output text format
mtcars %>%
table_grouped_summary(.,
var_names = c("disp", "hp", "drat", "mpg", "wt"),
grouping_variable = "cyl",
html_output = FALSE,
total = TRUE)
# without overall total
mtcars %>%
table_grouped_summary(.,
var_names = c("disp", "hp", "drat", "mpg", "wt"),
grouping_variable = "cyl",
html_output = FALSE,
total = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.