fmt_2stats: Format content for data generated with summarizor()

View source: R/summarizor.R

fmt_2statsR Documentation

Format content for data generated with summarizor()

Description

This function was written to allow easy demonstrations of flextable's ability to produce table summaries (with summarizor()). It assumes that we have either a quantitative variable, in which case we will display the mean and the standard deviation, or a qualitative variable, in which case we will display the count and the percentage corresponding to each modality.

Usage

fmt_2stats(stat, num1, num2, cts, pcts, ...)

fmt_summarizor(stat, num1, num2, cts, pcts, ...)

Arguments

stat

a character column containing the name of statictics

num1

a numeric statistic to display such as a mean or a median

num2

a numeric statistic to display such as a standard deviation or a median absolute deviation.

cts

a count to display

pcts

a percentage to display

...

unused arguments

See Also

summarizor(), tabulator(), mk_par()

Other text formatter functions: fmt_avg_dev(), fmt_dbl(), fmt_header_n(), fmt_int(), fmt_n_percent(), fmt_pct(), fmt_signif_after_zeros()

Examples

library(flextable)
z <- summarizor(iris, by = "Species")

tab_1 <- tabulator(
  x = z,
  rows = c("variable", "stat"),
  columns = "Species",
  blah = as_paragraph(
    as_chunk(
      fmt_summarizor(
        stat = stat,
        num1 = value1, num2 = value2,
        cts = cts, pcts = percent
      )
    )
  )
)

ft_1 <- as_flextable(x = tab_1, separate_with = "variable")
ft_1 <- labelizor(
  x = ft_1, j = "stat",
  labels = c(
    mean_sd = "Moyenne (ecart-type)",
    median_iqr = "Mediane (IQR)",
    range = "Etendue",
    missing = "Valeurs manquantes"
  )
)
ft_1 <- autofit(ft_1)
ft_1

davidgohel/flextable documentation built on April 18, 2024, 11:37 a.m.