0

So I have these two dataframes:

id <- c(1, 2, 3, 4, 5, 6, 7, 8)
drug <- c("A", "B", "C", "D", "E", "F", "G", "H")
value <- c(100, 200, 300, 400, 500, 600, 700, 800)
df1 <- data.frame(id, drug, value)

id <- c(1, 2, 3, 4, 6, 8)
treatment <- c("C", "IC", "C", "IC", "C", "C")
value <- c(700, 800, 900, 100, 200, 900)
df2 <- data.frame(id, treatment, value)

I used merge() to combined the two datasets like this

key = "id"
merge(df1,df2[key],by=key)

This worked but I end up droping some fields(due to not matching ids). Is there a way I can see or collect the ids which were dropped as well? My real dataset consists of 100s of entries so finding a way to find dropped ids would be very useful in R

1 Answers1

0
library(dplyr)

> anti_join(df1, df2, by = "id")
  id drug value
1  5    E   500
2  7    G   700

Or if you just want the IDs

> anti_join(df1, df2, by = "id")$id
[1] 5 7
Eugene Chong
  • 1,591
  • 5
  • 16