table_grouped_summary: Grouped Summary Table with optional html output

View source: R/table_grouped_summary.R

table_grouped_summaryR Documentation

Grouped Summary Table with optional html output

Description

Grouped Summary Table with optional html output

Usage

table_grouped_summary(
  df,
  var_names,
  grouping_variable,
  html_output = FALSE,
  total = TRUE
)

Arguments

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

Value

A text table with grouped summary

See Also

sprintf, mean, sd, htmlTable

Examples

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)

JMLuther/tabletools documentation built on July 1, 2024, 2:01 p.m.