I want to change level name (eg "Africa " ) to another already available level (eg "Africa") in categorical variable (e.g. with the same descriptor, some factors have trailing whitespace while others do not). These variables, in the Continent column, are currently stored as factors in a dataframe.
Here are the output of my gigantic dataset
I tried series ifelse but I got weird results:
data.CONTINENT$Continent_R<- ifelse (data.CONTINENT$Continent=="Africa ","Africa",
ifelse (data.CONTINENT$Continent=="Asia ","Asia",
ifelse (data.CONTINENT$Continent=="Europe ","Europe",
ifelse (data.CONTINENT$Continent=="Europe ","Europe",
ifelse (data.CONTINENT$Continent=="Multi ","Multi",
ifelse (data.CONTINENT$Continent=="North America ","North America",
ifelse (data.CONTINENT$Continent=="South America ","South America",
data.CONTINENT$Continent))))))); table (data.CONTINENT$Continent_R)
Here is what I got based on the prior code:
Any Advice will be greatly appreciated.