lbl_add: Add labels for unlabelled values

Description Usage Arguments Value See Also Examples

View source: R/lbl_helpers.r

Description

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

Usage

1
2
3
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::labelled vector

See Also

Other lbl_helpers: lbl_clean(), lbl_collapse(), lbl_define(), lbl_na_if(), lbl_relabel(), lbl(), zap_ipums_attributes()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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))

ipumsr documentation built on July 22, 2020, 1:06 a.m.