I have two data frame, df8, df9, now i am checking if "name" column in df8 is blank or space or NA then mutate new column "blank_name" as 1, else 0 but i don't want to change the original column "Name" for city in (CY) .I am trying the below way but doesn't work for me.
also I want to check if id of df8 present in df9 then i want to check if name is consistent with name in df9
I am trying like below, the common column is df9[id] and df8[code]
df9 <- data.frame(id=c(3109,2357,4339,8927,9143,4285,2683,8217,3702,7857,3255,4262,8501,7111,2681,6970),
name=c("try,xab","xab,Lan","mhy,mun","vgtu,mmc","dgsy,aaf","kull,nnhu","hula,njam","mund,jiha","htfy,ntha","","sgyu,hytb","vdti,kula","mftyu,huta","","cday,bhsue","ajtu,nudj"))
df8 <- data.frame(code=c(3109,2357,4339,8927,9143,4285,2683,8217,3702,7857,3255,4262,8501,7111,2681,6970),
city = c("CY","NY","DA","CY","MN","GA","MN","CY","NY","DA","CY","CY","GA","CY","LA","DA"),
name=c("try,xab","xab,Lan","mhy,mun","vgtu,mmc"," ","kull,nnhu","hula,njam","mund,jiha","htfy,ntha",NA,"sgyu,hytb","vdti,kula","mftyu,huta","","cday,bhsue","ajtu,nudj"))
df8 <- df8 %>%
mutate(
name=if_else(city=="CY", name, str_trim(name)),
blank = case_when(
is.na(name)~1,
str_length(name)==0~1,
TRUE~0
)
)
df9 %>%
rename(name.9=name) %>%
right_join(df8_update, by=c("id"="code") %>%
mutate(if_name_ok= case_when(
is.na(name) & is.na(name.9)~ 0,
is.na(name) & blank==1 ~0,
name == name.9 ~0,
name != name.9~1,
TRUE ~ NA_real_
))
the output should be two mutated column with values 0 and 1 for True and False