check if records are same with previous data frame

I want to check two data frames records if they are same if not same then filter out the records and save the records in excel files.

for example if ANA2719 is not available in df2 but available in df then filter out the row and save as xlsx file

vise versa for the same KTN2542 is not present in df2 but present in DF then filter out the whole row and save as xlsx file

Note: weather any column can be lower case or upper . i mean it should also take care of upper case and lower case

df <- data.frame(ID =c("DEV2962","KTN2252","ITI2624","DEV2698","HRT2921","","KTN2624","ANA2548","ITI2535","DEV2732","HRT2837","ERV2951","KTN2542","ANA2813","ITI2210","KTN2542"),
                 Name= c("dev,akash","singh,rahul","lal,ram","singh,nkunj","garg,prabal","ali,sanu","singh,kunal","tomar,lakhan","thakur,praveen","ali,sarman","khan,zuber","singh,giriraj","sharma,lokesh","pawar,pooja","sharma,nikita","shivam"))

df2 <- data.frame(ID =c("DEV2962","KTN2251","ANA2719","ITI2624","DEV2698","HRT2923","","KTN2624","ANA2548","ITI2535","DEV2732","HRT2837","ERV2951","KTN2542","ANA2813","ITI2210"),
                  Name= c("dev,akash","singh,rahul","abbas,salman","lal","singh,nkunj","garg","ali,sanu","singh,kunal","tomar,lakhan","thakur,praveen","ali,sarman","khan,zuber","singh,giriraj","sharma,lokesh","pawar,pooja","sharma,nikita"))

the output i want to save in excel file as "records not in df"

enter image description here

in second sheet , list of records output "records not in df2"

enter image description here

Hi @shoaibali,
Following on from my earlier reply (and using that data) you can find mis-matches, and write them to an Excel file using:


anti_join(df, df1, by="ID") -> in_df_not_df1
anti_join(df1, df, by="ID") -> in_df1_not_df

write_xlsx(x=in_df_not_df1, path="output_1.xlsx")
write_xlsx(x=in_df1_not_df, path="output_2.xlsx")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.