Issues retaining labels after importing SPSS data

Hi there,

I'm reasonably new to R and having some difficulty importing an SPSS file the way I would like. I first tried using the haven package and the read_sav() function. This was able to import my file successfully. I wanted to keep the variable and value labels just as they were saved in the SPSS file, so i used as_factor() which retained these labels. But then when I went to create simple frequency tables using the count() function, the labels did not appear in the output (see screenshot).

So I then tried the foreign package instead using the following code to import the file:

df <- ("./folder/filename.sav",
                 = TRUE,
                          use.value.labels = TRUE)

But this gave me an error message - error reading system-file header. I've done a bit of googling and have been unable to find what the issue is. I've heard that haven is the better package so am happy to stick with that one, but still can't figure out why my frequency table isn't giving the proper labels (e.g. under 16 etc.)

Thanks in advance :pray:

please share representative example data that forum users can run.
Looking at what you have, that would be something like the output you receive when you run the code:


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.