Creating a new variable depending on another variable value in R


#1

I am trying to create a new variable depending on another variable value using following code…

comb$Geo_Area[comb$native.country %in% c(“China”,“Hong”,“India”,“Iran”,“Japan”, “Laos”,“Philippines”,“Taiwan”,“Thailand”,“Vietnam”)] = “Asia”

But this is not working…
still getting NA values in the column…

Plz suggest something…

Thanks
Ashis


#2

Hi
if do
unique(comb$native.country[is.na(comb$Geo_Area)] what do you get ? Do you have some names which are in c(“China”,“Hong”,“India”,“Iran”,“Japan”, “Laos”,“Philippines”,“Taiwan”,“Thailand”,“Vietnam”) if not not then you know
if yes mystery !!!
Alain


#3

Always mention if there was or wasn’t some error/warning when something unexpected happens. The above could be as a result of the column being factor. What output does the below give?

is.factor(comb$Geo_Area)