(Here and here similar questions, but for python.)
I have two lists of equal length, each list containing character vectors. I want to contrast the lists, position by position, to test whether they have common elements.
list_1 <- list(c("a","b"), c("a","c"))
list_2 <- list(c("a","x"), c("p","q"))
> list_1
[[1]]
[1] "a" "b"
[[2]]
[1] "a" "c"
> list_2
[[1]]
[1] "a" "x"
[[2]]
[1] "p" "q"
This is likely a lapply problem, but I'm not sure how to tackle it. Here's an attempt that does not work:
> lapply(list_1, function(x){any(x %in% list_2)})
[[1]]
[1] FALSE
[[2]]
[1] FALSE
The expected solution is:
[[1]]
[1] TRUE
[[2]]
[1] FALSE
Help?