# make a "Likert"-type fake data set to demo
# note, by default, add_val_labs() "vars" arg will do partial matching
# in this case, we catch all vars with "x" in their name
set.seed(272)
dflik <- make_likert_data(scale = 1:7)
vals2label <- 1:7
labs2use <- c(
"VSD",
"SD",
"D",
"N",
"A",
"SA",
"VSA"
)
dflik <- add_val_labs(
data = dflik, vars = c("x", "y3"), # note the vars args
vals = vals2label,
labs = labs2use,
partial = TRUE
)
dfdrop <- drop_val_labs(dflik,
vars = c("x2", "y3"),
partial = FALSE
)
# var x2's value labels are gone, like we asked for
get_val_labs(dfdrop, "x2")
# var x1's value labels are intact, b/c we didn't ask to drop them
get_val_labs(dfdrop, "x1")
dfxgone <- drop_val_labs(dflik,
c("x"),
partial = TRUE
)
# still a lot of value labels, but all are for "y" vars,
# ...none is left for "x" vars
get_val_labs(dfxgone)
Run the code above in your browser using DataLab