I have used haven to import an SPSS data file. I need to export it to Excel and retain the variable labels. Could I please get some help with this?

Sorry, I am completely new with using R Studio and have spent the better part of the morning trying to figure this out. I have imported an SPSS datafile into R Studio. All I want to do is export this to an excel file and retain the variable labels for each variable.

library(haven)
abc123 <- read_sav("S:/datafiles/abc123.sav")
View(abc123)

 Gdr                 R1                   R2                      R3

Gender White Black Asian

This looks like it might work. With "expss" installed see ?read_labelled_xlsx for some information.

With your data.frame or tibble called dat1 and your Excel file mydata.xlsx.

install.packages("expss")  

library(expss)

write_labelled_xlsx(dat1, "mydata.xlsx",
  data_sheet = "data",
  dict_sheet = "dictionary",
  remove_repeated = FALSE,
  use_references = TRUE
)

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.