dimanche 13 septembre 2020

conditional creation of variable in R [duplicate]

I would like to create a country column in to the existing dataframe named data1. it has to be done by the unique values in the SITEN column. I have tried below mentioned code , but unable to find the exact error behind it.

Anyone who helps to resolve will be highly appreciated.

data1$COUNTRY<- if((data1$SITEN %in% c(101,102,103,104,206,105,106,207, 209, 210, 208)), "INDIA",
                if((data1$SITEN %in% c(311,312,313,314,315)),"SRILANKA",
                if((data1$SITEN %in% c(415,416,417, 418 )),"foreigner"))

Aucun commentaire:

Enregistrer un commentaire