fmt_2stats: Format summarizor statistics as text

View source: R/summarizor.R

fmt_2statsR Documentation

Format summarizor statistics as text

Description

Format the output of summarizor() into display strings: quantitative variables are shown as mean (sd), median (IQR), or range; qualitative variables are shown as count (percentage).

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 value formatters: 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

flextable documentation built on June 2, 2026, 9:08 a.m.