1

I'm having a problem with a very simple issue and I don't know how to sort it out. Here's the deal. I have two one column data frames

a <- data.frame(C=c("c1","c2","c3","c4","c5","c6","c7","c8"))
b <- data.frame(C=c("c1","c4","c5","c8"))

I would like to get one column dataframe with the entries that do NOT appear in b but they are in a. ie. a dataframe with "c2","c3","c6","c7". I tried

c <- setdiff(a,b)

but I got the a dataframe and also with

c <- merge(a,b,all.x=TRUE)

I don't get what I want it. so do you know where I am wrong?

Jaap
  • 77,147
  • 31
  • 174
  • 185
Stefano
  • 351
  • 4
  • 18

1 Answers1

4

We can use anti_join

library(dplyr)
anti_join(a,b)

Or

data.frame(C= setdiff(a[,1], b[,1]))
akrun
  • 789,025
  • 32
  • 460
  • 575