1

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.

Victor Nielsen
  • 443
  • 2
  • 14
  • A replication of what's happening could help with understanding your problem. It's not clear how you imported the file. – Pedro Mar 11 '22 at 14:36
  • @Pedro I added more info. Since it happens with any mutation, I assume it is a general enough issue to not need a dataset. – Victor Nielsen Mar 11 '22 at 18:45

0 Answers0