I am using haven::labelled to set value labels of a variable. The goal is to create a fully documented dataset I can export to SPSS.
Now, say I have a df value_labels of values and their value labels. I also have i df df_data with variables to which I want allocate value labels.
value_labels <- tibble(
value = 1:6,
labels = paste0("value", 1:6)
)
df_data <- tibble(
id = 1:10,
var = floor(runif(10, 1, 6))
)
Manually, I would create value labels for df_data$var like so:
df_data$var <- haven::labelled(df_data$var, labels = c(values1 = 1, values2 = 2, values3 = 3, values4 = 4, values5 = 5, values6 = 6))
But since I have more than 16 datasets with close to 7 000 columns I need a more dynamic way of assigning value labels. Note that there is, as i understand it, difference between "values1" = 1 and values1 = 1 (quotations marks), depending on the variable class.
Note that I use haven::labelled since it is the only way, so far, I have been able to successfully export a .sav-file with value labels. I have tried sjlabelled, but with no luck.