Learn R Programming

GimmeMyStats (version 1.0.0)

print_multinomial: Prints descriptive statistics for multinomial variables

Description

Calculates and prints frequency counts and percentages for multinomial (multi-level) categorical variables.

Usage

print_multinomial(x, label = NULL, digits = 1, width = 15, n = nrow(x), ...)

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.

Arguments

x

Data frame, matrix, or vector containing multinomial variables.

label

Character vector specifying the names of the categorical variables.

digits

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

width

Integer specifying the maximum width for wrapping text.

n

Integer specifying the total number of observations.

...

Additional arguments passed to count_category.

Examples

Run this code
x <- data.frame(A = sample(c("X", "Y", "Z"), 100, replace = TRUE))
print_multinomial(x, label = "A")
x2 <- rbind(x, data.frame(A = rep("Level A", length(x[x == "Level X", ]))))
print_multinomial(
    x,
    label = "Variable A",
    sort = FALSE,
    n = 90,
    digits = 2,
    width = 5
)

Run the code above in your browser using DataLab