What I'm tried is to detect string, but I failed.
The task I need is to update a phone only if the new number is new.
The original number is phone1, the updated number is phone2.
So, I asked if the updated phone is new, repeat that number in phone3.
If they are the same, or it's contained in phone1, assign as "NA" the phone3 value.
library(stringr)
phone1=c("123784569","14785236","181232356","56915348789","754132538","186578452155","5421312654","456523221285")
phone2=c("97856526","8114785236","22/181232356","62145412","754132538","6578452155","5421312654","7824521285/456523221285")
dataz=data_frame(phone1,phone2)
dataz
dataz=dataz %>% mutate(phone3=ifelse(phone1==phone2,phone1,phone2))
dataz=dataz%>% mutate(phone3=str_replace_all(dataz$phone3,dataz$phone2,dataz$phone2) )%>% print()
dataz=dataz%>%mutate(phone3desired=c("97856526",NA,NA,"62145412",NA,NA,NA,"7824521285")) %>% print()
The issue was the task doesn't seem easy for me now. Phone3desired is the result I intend to get.
Also, sometimes phone2 is larger than phone1, or vice versa, by the area number. So, phone1 contains phone2 or phone2 contains phone1. Sometimes I received two numbers in phone2, but only one of them was declared and shoud be removed. The variable phone3desired is clear.
Thanks for your time and interest.