I assume I will have to rewrite the previous code into a matching function, that only replaces if there is a match.
How should I match the labels with the new data frame if they exist?
CodePudding user response:
This is not super pretty, but you can use match
to look up the variables that have labels and then only update those
matches <- match(names(df2), Lbl$Varcode)
for (i in seq_along(matches)) {
if (!is.na(matches[i]))
label(df2[[i]]) <- Lbl$Variables[matches[i]]
}