vals: Create tidy dataframe that summarizes frequency of values in...

View source: R/vals.R

valsR Documentation

Create tidy dataframe that summarizes frequency of values in a vector

Description

Akin to 1-dimensional table with a few differences: it returns as a dataframe, it always includes NAs, it includes the proportion of elements, it can take a vals(df, var) input format for easy chaining, it will include value labels when sjlabelled::is_labelled.

Usage

vals(data, var = NULL, digits = 2)

Arguments

data

Either a vector, or a dataframe in which to find var.

var

When data is a dataframe, bare or quoted name of column to use.

digits

Optional argument to round proportions to specific number of digits (default is 2).

Details

Note that the cum.prop column in resulting dataframe was calculated after sorting based on value. It will not remain correct if resorted.

Examples

# first input format uses a (df, name) specification like dplyr
vals(mtcars, gear)

# second input format just takes a vector
vals(mtcars$gear)

# with NAs
vals(mice::boys, gen)

# with more decimals in proportions
vals(mice::boys$gen, digits = 3)

wepelham3/sack2 documentation built on Aug. 5, 2023, 5:53 a.m.