I have a list of observation labels that goes with a .csv data set, e.g., 1 = "Yes", 0 = "No", where the label for all observations equal to 1 for column k has the label of "Yes" but retains the underlying numerical value of 1 or 0.
I want to iteratively add labels to my dataset using this list, ideally using purrr or the tidyverse.
Here is an example of what I am trying to do, but at scale across multiple columns.
# load packages
library(tidyverse)
library(sjlabelled)
# load package data
data(efc)
# let's just start with a basic data frame
efc_twovar <- efc %>% select(e42dep, e15relat)
# create a list of labels
lab_list <- list(attr(efc$e42dep, "labels"), attr(efc$e15relat, "labels"))
# remove the labels from our data set
attr(efc_twovar, "labels") <- ""
# basic set up
set_labels(efc_twovar$e42dep, labels = lab_list[1])
# purrr attempt
map(efc_twovar, set_labels, labels = lab_list)
The purrr attempt above results in the labels from the first vector in the list getting applied to both columns in the data frame rather than just the first. I ultimately want to do this with a list of about 20 label vectors for as many columns.