Learn R Programming

ipumsr (version 0.4.2)

lbl_add: Add labels for unlabelled values

Description

Add labels for values that don't already have them.

Usage

lbl_add(x, ...)

lbl_add_vals(x, labeller = as.character, vals = NULL)

Arguments

x

A labelled vector

...

Labels formed by lbl indicating the value and label to be added.

labeller

A function that takes a single argument of the values and returns the labels. Defaults to as.character. as_function, so also accepts quosure-style lambda functions. See examples for more details.

vals

Vector of values to be labelled. NULL, the default labels all values that are in the data, but aren't already labelled.

Value

A haven::labeled vector

See Also

Other lbl_helpers: lbl_clean, lbl_collapse, lbl_na_if, lbl_relabel, lbl, zap_ipums_attributes

Examples

Run this code
# NOT RUN {
x <- haven::labelled(
  c(100, 200, 105, 990, 999, 230),
  c(`Unknown` = 990, NIU = 999)
)

lbl_add(x, lbl(100, "$100"), lbl(105, "$105"), lbl(200, "$200"), lbl(230, "$230"))

lbl_add_vals(x)
lbl_add_vals(x, ~paste0("$", .))
lbl_add_vals(x, vals = c(100, 200))

# }

Run the code above in your browser using DataLab