I am trying to do a kind of 'if' statement in R where I want to find if two values (string) are the same in two different columns. For example, if my Origin and my Destination country are the same, I want to create a new column with Domestic as a result. If false, then eventually I would code the NA as International.
I try several functions in R but still can't have it properly!
I think the recode function from car library could fit. Here is an example of data and two examples of lines of code I have tried. Thanks for the help.
#Data
Origin.Country <- c("Canada","Vietnam","Maldives", "Indonesia", "Spain", "Canada","Vietnam")
Passengers <- c(100, 5000, 200, 10000, 200, 20, 4000)
Destination.Country <- c("France","Vietnam","Portugal", "Thailand", "Spain", "Canada","Thailand")
data2<-data.frame(Origin.Country, Destination.Country, Passengers)
#Creating new column
data2$Domestic<-NA
#If Origin and Destination is the same = Domestic
data2$Domestic[data2$Origin.Country==data2$Destination.Country <- Domestic
data2$Domestic <- recode(data2$Origin.Country, c(data2$Destination.Country)='Domestic', else='International')