I have a dataset with a lot of variables that need to have its values labelled. I know how to add labels to their values one by one but I would like to incorporate a loop, which could automatically assign a label to a value of 1 (1 indicates that someone selected an option, for instance they have depression, while 0 means that they didn't select it) across several variables that are dsm_00 (where 1 is supposed to be labelled as "no diagnosis"), dsm_01 (1 is depression), dsm_02 (1 is anxiety) and so on up until dsm_34.
I have created a list of names to be assigned:
labels <- list("no diagnosis", "depression", "anxiety", "bipolar", ....).
And I have a code for how to do it one by one:
val_lab(mydat$dsm_00) = num_lab("
1 no diagnosis
")
I'm not sure how I would incorporate it as a loop (I have always struggled with those). Any help would be appreciated!