fmt_n_percent: Format content for count data

View source: R/summarizor.R

fmt_n_percentR Documentation

Format content for count data

Description

The function formats counts and percentages as ⁠n (xx.x%)⁠. If percentages are missing, they are not printed.

Usage

fmt_n_percent(n, pct, digit = 1)

Arguments

n

count values

pct

percent values

digit

number of digits for the percentages

See Also

tabulator(), mk_par()

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

Examples

library(flextable)

df <- structure(
  list(
    cut = structure(
      .Data = 1:5, levels = c(
        "Fair", "Good", "Very Good", "Premium", "Ideal"
      ),
      class = c("ordered", "factor")
    ),
    n = c(1610L, 4906L, 12082L, 13791L, 21551L),
    pct = c(0.0299, 0.0909, 0.2239, 0.2557, 0.3995)
  ),
  row.names = c(NA, -5L),
  class = "data.frame"
)

ft_1 <- flextable(df, col_keys = c("cut", "txt"))
ft_1 <- mk_par(
  x = ft_1, j = "txt",
  value = as_paragraph(fmt_n_percent(n, pct))
)
ft_1 <- align(ft_1, j = "txt", part = "all", align = "right")
ft_1 <- autofit(ft_1)
ft_1

flextable documentation built on Oct. 30, 2024, 9:15 a.m.