I have a dataframe (df1) with multiple columns (ID, Number, Location, Field, Weight). I also have another dataframe (df2) with more information (ID, PassRate, Number, Weight). <
From the question and sample code, it is unclear whether you want df_sub
to contain the rows in df1
which do have matches in df2
, or the ones without matches. dplyr::semi_join()
will return the rows with matches, dplyr::anti_join()
will return the rows without matches.
df_sub <- semi_join(x=df1, y=df2, by=c("ID","Weight"))
or
df_sub <- anti_join(x=df1, y=df2, by=c("ID","Weight"))