简体   繁体   中英

Error in .subset2(x, i, exact = exact) : recursive indexing failed at level 2

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 DG, 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM