tab_spread {tabxplor}R Documentation

Spread a tab, passing a tab variable to column

Description

Spread a tab, passing a tab variable to column

Usage

tab_spread(
  tabs,
  spread_vars,
  names_prefix,
  names_sort = FALSE,
  totname = "Total"
)

Arguments

tabs

A tibble of class tab, made with tab, tab_many or tab_plain.

spread_vars

<tidy-select> The tab variables to pass to column, with a syntax of type c(var1, var2, ...).

names_prefix

String added to the start of every variable name.

names_sort

If no names_prefix is given, new names takes the form spread_var_col_var_level. Should then the column names be sorted ? If FALSE, the default, column names are ordered by first appearance.

totname

The new name of the total rows, as a single string.

Value

A tibble of class tab, with less rows and more columns.

Examples

 data <- forcats::gss_cat %>% dplyr::filter(year %in% c(2000, 2014))

tabs <-
  tab(data, relig, marital, c(year, race), pct = "row", totaltab = "no",
      color = "diff", tot = "row", rare_to_other = TRUE)

tabs %>%
  dplyr::select(year, race, relig, Married) %>%
  tab_spread(race)
  

[Package tabxplor version 1.1.3 Index]