Finding and subsetting duplicates from two sources

This can be done with setops functions (see help(setops))

intersect(1:5, 4:8)
#> [1] 4 5
union(1:5, 4:8)
#> [1] 1 2 3 4 5 6 7 8

setdiff(1:5, 4:8)
#> [1] 1 2 3
setdiff(4:8, 1:5)
#> [1] 6 7 8

If you have trouble with this, see the FAQ: How to do a minimal reproducible example reprex for beginners and we can circle back.

2 Likes