I would like to use the attributes of the dataset to recode my spss data while preserving the metadata/label attributes. The problem I am having is that anything I do removes the existing attributes while trying to recode the numeric values of my data into the text.
For example the variable AWR_A_5 below the 1's correspond to 'Kelley Blue Book'
testfile <- haven::read_sav("TestFile.sav")
> savfile$AWR_A_5
<labelled<double>[10]>: Which of the following automotive resource sites, if any,
have you heard of? Please select all that apply. Kelley Blue Book
[1] NA NA 0 NA NA 1 1 NA 1 0
Labels:
value label
1 Kelley Blue Book
So I would like to recode those 1's in the data to Kelley Blue Book while retaining the attributes. So it would look like the following. I understand this would change the column type from numeric to character.
> savfile$AWR_A_5
<labelled<character>[10]>: Which of the following automotive resource sites, if any,
have you heard of? Please select all that apply. Kelley Blue Book
[1] NA NA 0 NA NA Kelley Blue Book Kelley Blue Book NA Kelley Blue Book 0
Labels:
value label
1 Kelley Blue Book
One option to achieve your desired result would be to convert both the values or the data type and the labels to characters (as I deal regularly with such transformations I wrapped this code inside a function).
Using some fake random example data: