Skip to contents

The type of frequency table depends on the number of selected columns:

Cross tabulations:

By default, if you provide two column selections, the second column is treated as categorical. Setting the metric-parameter to TRUE will call the appropriate functions for correlation analysis:

Parameters that may be passed to specific count functions:

  • ci: Add confidence intervals to proportions.

  • percent: Frequency tables show percentages by default. Set to FALSE to get raw proportions.

  • prop: For cross tables you can choose between total, row or column percentages.

  • values: The values to output: n (frequency) or p (percentage) or both (the default).

  • category: When you have multiple categories in a column, you can focus one of the categories to simplify the plots. By default, if a column has only TRUE and FALSE values, the outputs focus the TRUE category.

  • labels: Labels are extracted from the column attributes. Set to FALSE to output bare column names and values.

[Experimental]

Usage

tab_counts(data, cols, cross = NULL, metric = FALSE, clean = TRUE, ...)

Arguments

data

A data frame.

cols

A tidy column selection, e.g. a single column (without quotes) or multiple columns selected by methods such as starts_with().

cross

Optional, a grouping column. The column name without quotes.

metric

When crossing variables, the cross column parameter can contain categorical or metric values. By default, the cross column selection is treated as categorical data. Set metric to TRUE, to treat it as metric and calculate correlations.

clean

Prepare data by data_clean.

...

Other parameters passed to the appropriate table function.

Value

A volker tibble.

Examples

library(volker)
data <- volker::chatgpt

tab_counts(data, sd_gender)
#> 
#> 
#> |Gender  |   n|    p|
#> |:-------|---:|----:|
#> |female  |  40|  40%|
#> |male    |  60|  59%|
#> |diverse |   1|   1%|
#> |total   | 101| 100%|