I imported a SPSS file into R using the haven package. As you can see on the next image, all variables have labels associated with them (e.g. "2016 YEAR OF ADMINISTRATION"):
I'm trying to read those labels, however using this line of code returns NULL:
attr(X36799_0001_Data[,15], "label")
ant this line of code also returns NULL:
attributes(X36799_0001_Data)$variable.labels
Any info on what I'm doing wrong would be hugely appreciated. Thank you!
Just change the way you are subsetting, and it should work.
attr(X36799_0001_Data[[15]], "label")
The explanation of this has to do with the way R subsets. An in depth explanation is here: Subsetting - Advanced R.
You can also use the package labelled
to deal with SPSS labels. In this case, using the var_label
.
var_label(X36799_0001_Data[, 15])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With