I uploaded an .sav file using haven.
df <- read_sav("file.sav", user_na = FALSE)
This makes sure that all the metadata including the labels are imported into r.
However, after running all my code (mutations etc.), I notice that all variables that had some kind of mutation have lost all the metadata. How can I make sure it doesn't get lost?
For example after doing this:
df <- df %>%
mutate(col1 = gsub('\\s+', '', toupper(col1)))
col1 would no longer have labels from library(labelled) It happens after any kind of mutation.