suppressPackageStartupMessages(library(dplyr))
df1 =data.frame(SAMPN =c(1,1,2,2), PERNO = c(2,3,2,4), other.column = 10:7)
df2 = data.frame(SAMPN = c(1,1,1,1,1,1,1,1,2,2,2,2,3),
PERNO = c(2,2,2,3,3,4,5,6,2,2,4,3,3),
other.column = c(10,7,9,7,9,7,5,9,9,8,3,1,0))
df2Filtered <- semi_join(df2, df1, by = c("SAMPN", "PERNO"))
AllDat <- rbind(df2Filtered, df1)
AllDatUnique <- unique(AllDat)
AllDatUnique
#> SAMPN PERNO other.column
#> 1 1 2 10
#> 2 1 2 7
#> 3 1 2 9
#> 4 1 3 7
#> 5 1 3 9
#> 6 2 2 9
#> 7 2 2 8
#> 8 2 4 3
#> 12 2 4 7
Created on 2019-09-18 by the reprex package (v0.2.1)