I have imported a .sav file using the haven package and wanted to keep the value labels for a number of factors (as you can do this when bringing in SPSS data but not with CSV data). This worked fine with no issues.
One of my multi-response variables (profession) is also a factor, however I want to make this numeric as I want to create a new variable that sums up the number of professions an individual has (there are 29 different options available, thus 29 separate variables for profession). However, when I try to change this back for one of the professions listed using as.numeric(), it doesn't seem to work (the variable is still a factor).
What can I do to convert this variable so I can treat it as numeric? (i.e consisting of 0s for those who did not select the profession, and 1s for those who did).
Below is the code I used.
Well, the problem you are trying to solve i.e. to get the count of professions one person is associated with, for that it is not necessary to convert a factor column to numeric. You can find that count with factor as well. Let me explain that with an example:
Regarding your second question, why the column is still factor, that may be because you are not overriding that column in dataframe i.e. you may need to do:
kindly upvote the answer, if you found this helpful.