I'd like to stick with dplyr()
if possible (I'm a major fan), or base R is fine too if the solution is simple.
Suppose you have two data frames, as shown below. I'd like to create a new data frame that compares the two (df1
and df2
), and only shows those complete rows from df1
whose ID doesn't appear in the ID's shown in df2
. df2
serves as the "knock out" list. How would this be done?
df1 <- data.frame(
ID = c(1,2,3,4,5),
Value = c(10,20,30,40,50)
)
df2 <- data.frame(
ID = c(6,7,8,1,2),
Value = c(60,70,80,10,20)
)
The new data frame, call it df3
, would look like this after applying the df2
"knock outs", when run in the R studio console:
ID Value
1 3 30
2 4 40
3 5 50
ID's 1 and 2 got knocked out because they appear in both df1
and df2
.