I have been working with the Titanic dataset from Kaggle. I have been trying to use an ifelse condition with an aim to do some feature engineering work but unfortunately I have been struck with my if else condition which is not producing an error but at the same time not working at all. What am I doing wrong and how do I deal with it? Here is my code:
if(train$titles=="Dr" && train$Sex=="male"){
train$titles<-"Mr"
}else if(train$titles=="Dr" && train$Sex=="female"){
train$titles<-"Mrs"
}
Here is my output which is the same before and after:
> table(train$titles)
Mr Mrs Dr Miss
571 128 7 185
Is this because I have left out the final else condition?
The thing is if the conditions in the if else don't match at all then I don't want to change the values in the column(i.e. I want them to be as it is). What do I do?