Learn R Programming

flextable (version 0.9.11)

fmt_2stats: 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 text formatter functions: fmt_avg_dev(), fmt_dbl(), fmt_header_n(), fmt_int(), fmt_n_percent(), fmt_pct(), fmt_signif_after_zeros()

Examples

Run this code
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

Run the code above in your browser using DataLab