I have 2 data frames df1
and df2
.
df1 <- data.frame(c1=c(\"a\",\"b\",\"c\",\"d\"),c2=c(1,2,3,4) )
df2 <- data.frame(c1=c(\"
You can create identifier columnas then subset:
e.g.
df1 <- data.frame(c1=c("a","b","c","d"),c2=c(1,2,3,4), indf1 = rep("Y",4) )
df2 <- data.frame(c1=c("c","d","e","f"),c2=c(3,4,5,6),indf2 = rep("Y",4) )
merge(df1,df2)
# c1 c2 indf1 indf2
#1 c 3 Y Y
#2 d 4 Y Y
bigdf <- merge(df1,df2,all=TRUE)
# c1 c2 indf1 indf2
#1 a 1 Y
#2 b 2 Y
#3 c 3 Y Y
#4 d 4 Y Y
#5 e 5 Y
#6 f 6 Y
Then subset how you wish:
bigdf[is.na(bigdf$indf1) ,]
# c1 c2 indf1 indf2
#5 e 5 Y
#6 f 6 Y
bigdf[is.na(bigdf$indf2) ,] #<- output you requested those not in df2
# c1 c2 indf1 indf2
#1 a 1 Y
#2 b 2 Y