Combine N and Percent Columns for Accessibility

combine_n_pct(df, n, pct, name, remove = TRUE, na_replace = NULL)

Arguments

df

A data frame that has already been sent to fmt_table()

n

The unquoted name of the column containing count values

pct

The unquoted name of the column containing percentage values

name

The name of the new combined column to be created

remove

Logical. Should the existing n and pct columns be removed?

na_replace

Character string representing how missing values should be represented.

Value

A data frame.

Examples

pcts <- tibble::tibble(Program = c("A", "B", "C", "D", "E", "F"),
               n = 0:5,
               p = 0.5 * (0:5))
pcts |>
  fmt_table() |>
  combine_n_pct(n = n, pct = p, name = "States")
#> # A tibble: 6 × 2
#>   Program States            
#>   <chr>   <chr>             
#> 1 A       "0\\ <(0.1)\\ \\ "
#> 2 B       "1\\ (0.5)"       
#> 3 C       "2\\ (1.0)"       
#> 4 D       "3\\ (1.5)"       
#> 5 E       "4\\ (2.0)"       
#> 6 F       "5\\ (2.5)"