Noah_Seagull
Noah_Seagull

Reputation: 377

Select unique characters present in one list in a list of lists

I am trying to filter all the characters that are present in a that are not present in b and c. I want to do this from the list l.

a<-c("A", "B", "C", "D", "E")
b<-c("A", "E", "I", "O", "U")
c<-c("H", "E", "L", "L", "O")
l<-list(a,b,c)

So the answer should be BCD.

Upvotes: 1

Views: 35

Answers (2)

akrun
akrun

Reputation: 887108

We could use setdiff as well

setdiff(l[[1]], unlist(l[-1]))
[1] "B" "C" "D"

Upvotes: 1

ThomasIsCoding
ThomasIsCoding

Reputation: 101335

you can try the code below

> d <- table(stack(setNames(l, seq_along(l))))

> row.names(d)[d[, 1] == 1 & rowSums(d) == 1]
[1] "B" "C" "D"
`` 

Upvotes: 1

Related Questions