make_wider: Pivot a table wider combining counts and percentages

View source: R/make_wider.R

make_widerR Documentation

Pivot a table wider combining counts and percentages

Description

This function takes a data frame produced by functions like build_table, build_mtable, or build_qtable, which contains columns N and Percent, and pivots it into a wider format. It combines the N and Percent columns into a single xlr_n_percent vector for each pivoted column. If top_variable is not specified, it infers the variable to use for column names from the structure of the data frame.

Usage

make_wider(x, top_variable = NULL, names_prefix = "")

Arguments

x

A data frame or tibble containing at least the columns N and Percent. Typically the output of build_table, build_mtable, or build_qtable,.

top_variable

Optional. A bare column name to use for the names_from argument in pivot_wider. If NULL (default), the function infers the column based the default position.

names_prefix

String added to the start of every variable name. This is particularly useful if top_variable is a numeric vector and you want to create syntactic variable names.

Value

A xlr_table (if x is a xlr_table) or tibble::tibble (if tibble::tibble or data.frame) in a wider format with columns containing xlr_n_percent vectors.

See Also

xlr_n_percent, pivot_wider

Examples

library(xlr)
# Assuming example data from build_table or similar
table <- clothes_opinions |>
            build_table(c(gender,age_group))
make_wider(table)

# use top_variable to specify that we have gender as out selection column
make_wider(table, top_variable = age_group)


xlr documentation built on Jan. 14, 2026, 9:09 a.m.