I'm using R and have a dataset with ~3000 psychological test data. Most of the data is stored as string variables:
> table(rona_full$FQ169_6)
At no time Some of the time Less than half the time More than half the time
418 73 48 36
Most of the time All of the time
20 9
I want to recode the string data into variables as such:
> table(rona_full$FQ169_6)
0 1 2 3 4 5
443 63 39 30 21 9
Currently, this is my approach:
rona_full$FQ169_6 <-ifelse(rona_full$MQ169_6 == "At no time", 0, #this recodes MDI from string
ifelse(rona_full$MQ169_6 == "Some of the time", 1,
ifelse(rona_full$MQ169_6 == "Less than half the time", 2,
ifelse(rona_full$MQ169_6 == "More than half the time", 3,
ifelse(rona_full$MQ169_6 == "Most of the time", 4, 5)))))
I imagine there is a more efficient way to perform this exact same recoding on 25+ columns rather than doing each one this way.