apply_labels: Set variable labels/value labels on variables in the...

View source: R/apply_labels.R

apply_labelsR Documentation

Set variable labels/value labels on variables in the data.frame

Description

apply_labels tries automatically detect what is variable label and what are value labels. See also var_lab and val_lab.

Usage

apply_labels(data, ...)

Arguments

data

data.frame/list

...

named arguments or lists. Name of argument is a variable name in the data. Argument values are variable or value labels. Unnamed characters of length 1 are considered as variable labels and named vectors are considered as value labels. List arguments should be named lists and contain value and variable labels.

Value

data with applied labels

Examples

data(mtcars)
mtcars = apply_labels(mtcars,
                      vs = "Engine",
                      vs = num_lab("
                             0 V-engine 
                             1 Straight engine
                             "),
                      am = "Transmission",
                      am = num_lab("
                             0 Automatic 
                             1 Manual
                             ")
)

# 'table' from base R
table(mtcars$vs, mtcars$am)

# more sophisticated crosstable
cross_cases(mtcars, vs, am)

# the same but with list argument
list_arg = list( vs = "Engine",
                 vs = num_lab("
                             0 V-engine 
                             1 Straight engine
                             "),
                 am = "Transmission",
                 am = num_lab("
                             0 Automatic 
                             1 Manual
                             ")
                 )

mtcars = apply_labels(mtcars, list_arg)


expss documentation built on July 26, 2023, 5:23 p.m.