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
.
CodePudding user response:
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"
``
CodePudding user response:
We could use setdiff
as well
setdiff(l[[1]], unlist(l[-1]))
[1] "B" "C" "D"