0

I have two vectors:

v1 <- c(1,2,3)
v2 <- c(4,5,6)

How can I check which (if any) elements in list1 is present in list2? The above case should return NULL.

Here's another case:

v1 <- c(1,2,3)
v3 <- c(3,4,5)

In this case, the answer should be 3.

Is there an elegant way to do this?

Thank you!

jo_
  • 677
  • 2
  • 11
  • 1
    Note that `intersect(v1, v2)` returns `numeric(0)`, not `NULL`. Check [here](https://stackoverflow.com/questions/7195248/what-is-the-difference-between-null-and-character0-in-r) for more on this – Maël Jun 30 '23 at 13:26

0 Answers0