Skip to contents

Calculates and prints frequency counts and percentages for binomial (two-level) categorical variables.

Usage

print_binomial(x, digits = 1, width = 15)

Arguments

x

Data frame, matrix, or vector containing binomial variables.

digits

Integer specifying the number of decimal places for the test statistic.

width

Integer specifying the maximum width for wrapping text.

Value

A tibble with one row per level for each categorical level containing the following columns:

Variables

Character vector specifying the name of each variable.

Levels

Character vector specifying the category level for each variable.

Statistics

Character vector combining the frequency count and the percentage for each level.

Examples

x <- data.frame(A = sample(c("X", "Y"), 100, replace = TRUE))
print_binomial(x)
#> # A tibble: 2 × 3
#>   Variables Levels Statistics
#>   <chr>     <chr>  <chr>     
#> 1 A         X      59 (59%)  
#> 2 A         Y      41 (41%)  
print_binomial(x, digits = 2, width = 5)
#> # A tibble: 2 × 3
#>   Variables Levels Statistics 
#>   <chr>     <chr>  <chr>      
#> 1 A         X      "59\n(59%)"
#> 2 A         Y      "41\n(41%)"