更新时间:2023-01-29 18:34:39
从问题和示例代码看,不清楚你是否希望 df_sub
包含 df1
中的行> 在 df2
中有匹配项,或者没有匹配项.dplyr::semi_join()
将返回匹配的行,dplyr::anti_join()
将返回不匹配的行.
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"))
或
df_sub <- anti_join(x=df1, y=df2, by=c("ID","Weight"))