Hi I have two dataframes (called table1 and table2 respectively):
ID MONTH
-- -----
1 Jan
2 May
3 May
4 Jan
ID TEST1 GNDR
-- ----- ----
1 90 M
2 80 M
3 70 F
where I want to remove from table1 any row where the ID matches the ID in table2, so that I am left with:
ID MONTH
-- -----
4 Jan
I just want to say where ID from table2 matches ID in table1, remove all rows relating to those IDs.
I can use the merge() function to obtain the rows where ID is common using
merge(table1,table2,by="ID")
and store the results in a dataframe, but I do not know how to delete the rows from table1 based on the result of the merge command.
Any help would be great.
You can use %in%
df1[!df1$ID %in% df2$ID,]
# ID MONTH
#4 4 Jan
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments