Reputation: 71
I am trying to recode my education variable from a factor with 18 levels to a factor with 7 levels,ranging from no qualification - GCSE D-G, GCSE A*-C- A Level -Undergraduate -Postgraduate - other.
bes[[bes$education]]%>% recode('No qualification' = 'no qualification',
'GCSE D-G, CSE grades 2-5, O level D-E' = 'GCSE D-G',
'Youth training certificate, skill seekers' = 'GCSE D-G',
'Clerical and commercial qualifications'= 'GCSE D-G',
'GCSE A*-C, CSE grade 1, O level grade A-C' = 'GCSE A*-C',
'Scottish Standard grades, Ordinary bands' = 'GCSE A*-C',
'Recognised trade apprenticeship' = 'GCSE A*-C',
'City&Guilds level 1, NVQ/SVQ 1 and equivalent' = 'GCSE A*-C',
'A level or equivalent '= 'A level',
'Scottish Higher or equivalent'= 'A level',
'City&Guilds level 2, NVQ/SVQ 2 and equivalent'= 'A level',
'HNC/HND, City&Guilds level 4, NVQ/SVQ 4/5'= 'A level',
'ONC/OND, City&Guilds level 3, NVQ/SVQ 3'= 'A level',
'Univ/poly diploma'= 'Undergraduate',
'First degree'= 'Undergraduate',
'Nursing qualification'= 'Undergraduate',
'Teaching qualification'= 'Undergraduate',
'Postgraduate degree' = 'Postgrad',
'Other technical, professional or higher qualification' = "Other")
I am having trouble doing so and I keep on getting error messages. I have tried using the ifelse function and various other functions both from base r and dplyr and plyr packages and I still can't seem to do it.
Upvotes: 1
Views: 868
Reputation: 469
The syntax of the first command is wrong. Instead of bes[[bes$education]]
use bes$education
. Square brackets [[]]
are to be used with numbers of columns and $
symbol with their names. It's either [[]]
or $
but not both.
Upvotes: 1