Once a left_join
is done, you cannot find out what wasn't matched. As Petr suggested in that answer, you can subsequently use anti_join
to find what doesn't match.
Another technique (that only requires one merge operation) is to do a full join and filter on elements unique to the left and to the right to see what is missing.
Using datasets used in the examples of full_join
:
full_join(band_members, band_instruments)
# Joining, by = "name"
# # A tibble: 4 x 3
# name band plays
# <chr> <chr> <chr>
# 1 Mick Stones <NA>
# 2 John Beatles guitar
# 3 Paul Beatles bass
# 4 Keith <NA> guitar
In this example, one can approximate the left-join with filter(!is.na(band))
and right-join with filter(!is.na(plays))
, and finally one can get the second frame's unmatched elements with filter(is.na(plays))
.
In this example, it's "clear" since there were no NA
values before the merge. If there is no column that is known to never be NA
(in either or both frames), then you can add one with low-cost. For instance mutate(band_members, orig=TRUE)
(and same for band_instruments
) will give you solid "known" columns.