tab_cts: Tabulate a dataframe's variables' value counts

View source: R/tab_functions.R

tab_ctsR Documentation

Tabulate a dataframe's variables' value counts

Description

Tabulate a dataframe's variables' value counts

Usage

tab_cts(df, id = "id", include_ids = FALSE)

Arguments

df

Dataframe

id

Character string of the id variable

include_ids

Logical denoting whether a list column ids should be included in the results. The ids in each list show at which values of id the variable var contains the value val.

Value

Dataframe consisting of columns var, val & n containing a tabulation of the counts of variables' values.

Examples

df <-
  tibble::tibble(
    fbnr = 1:10,
    sex = haven::labelled(c(2, 1, 2, 1, 1, 2, 2, 1, 2, 1),
                          label = "sex",
                          labels = c(MALES = 1, FEMALES = 2)),
    age = c(24, 23, 23, 41, 23, 39, 30, 18, 31, 48),
    marital = haven::labelled(
      c(1, 7, 2, 6, 4, 5, 3, 8, 4, 2),
      label = "marital status",
      labels = c(
        "single" = 1,
        "steady relationship" = 2,
        "living with partner" = 3,
        "married first time" = 4,
        "remarried" = 5,
        "separated" = 6,
        "divorced" = 7,
        "widowed" = 8
      )
    )
  )
tab_cts(df, "fbnr")

urswilke/tablab documentation built on Oct. 17, 2022, 8:19 p.m.