data(efc)
get_labels(efc$e42dep)
x <- add_labels(efc$e42dep, c(`nothing` = 5))
get_labels(x)
x <- add_labels(efc$e42dep, c(`nothing` = 5, `zero value` = 0))
get_labels(x, include.values = "p")
# replace old values
x <- add_labels(efc$e42dep, c(`not so dependent` = 4, `lorem ipsum` = 5))
get_labels(x, include.values = "p")
# replace values, alternative function call
replace_labels(x) <- c(`new second` = 2)
# replace specific missing value (tagged NA)
library(haven)
x <- labelled(c(1:3, tagged_na("a", "c", "z"), 4:1),
c("Agreement" = 1, "Disagreement" = 4, "First" = tagged_na("c"),
"Refused" = tagged_na("a"), "Not home" = tagged_na("z")))
# get current NA values
x
# tagged NA(c) has currently the value label "First", will be
# replaced by "Second" now.
replace_labels(x, c("Second" = tagged_na("c")))
Run the code above in your browser using DataLab