Is it possible to construct a list in R which has indices 'a','b','c'
but if you try to access it by any other index then it gives a specific value rather than an error?
I'm trying to use this to replace a bunch of nested ifelse
's and I need to do deal with the final else part.
[edit]
Here's the code I'm trying to replace
All_LDZ$GasRegion<- ifelse(All_LDZ$LDZ=='EA','East Anglia',
ifelse(All_LDZ$LDZ=='EM','East Midlands',
ifelse(All_LDZ$LDZ=='NE','North East England',
ifelse(All_LDZ$LDZ=='NO','North England',
ifelse(All_LDZ$LDZ=='NT','North Thames Area',
ifelse(All_LDZ$LDZ=='NW','North West England',
ifelse(All_LDZ$LDZ=='SC','Scotland',
ifelse(All_LDZ$LDZ=='SE','South East England',
ifelse(All_LDZ$LDZ=='SO','Southampton Area',
ifelse(All_LDZ$LDZ=='SW','South West England',
ifelse(All_LDZ$LDZ=='WM','West Midland',
ifelse(All_LDZ$LDZ=='WN','North Wales',
ifelse(All_LDZ$LDZ=='WS','South Wales', NA)))))))))))))
and I want something like
descriptiveRegionName <- list('EA'="East Anglia",
'EM'="East Midlands",
'NE'='North East England',
'NO'='North England',
'NT'='North Thames Area',
'NW'='North West England',
'SC'='Scotland',
'SE'='South East England',
'SO'='Southampton Area',
'SW'='South West England',
'WM'='West Midland',
'WN'='North Wales',
'WS'='South Wales',
ELSE = NA)
Note the ELSE index I made up.
[edit]
This question has been marked as a possible duplicate but I don't see how it's a direct duplicate.