v <- labelled(c(1,2,2,2,3,9,1,3,2,NA), c(yes = 1, no = 3, "don't know" = 9))
val_labels(v)
val_labels(v, prefixed = TRUE)
val_label(v, 2)
val_label(v, 2) <- 'maybe'
val_label(v, 9) <- NULL
val_labels(v) <- NULL
if (require(dplyr)) {
# setting value labels
df <- tibble(s1 = c("M", "M", "F"), s2 = c(1, 1, 2)) %>%
set_value_labels(
s1 = c(Male = "M", Female = "F"),
s2 = c(Yes = 1, No = 2)
)
val_labels(df)
# updating value labels
df <- df %>% add_value_labels(s2 = c(Unknown = 9))
df$s2
# removing a value labels
df <- df %>% remove_value_labels(s2 = 9)
df$s2
# removing all value labels
df <- df %>% set_value_labels(s2 = NULL)
df$s2
# example on a vector
v <- 1:4
v <- set_value_labels(v, min = 1, max = 4)
v
v %>% set_value_labels(middle = 3)
v %>% set_value_labels(NULL)
v %>% set_value_labels(.labels = c(a = 1, b = 2, c= 3, d = 4))
v %>% add_value_labels(between = 2)
v %>% remove_value_labels(4)
}
Run the code above in your browser using DataLab