Reputation: 665
I have two vectors containing strings:
names_1 <- c("A", "B", "C", "D")
names_2 <- c("C", "D", "E")
How do I know which strings from names_1 exist in names_2?
Upvotes: 0
Views: 55
Reputation: 87
which(names_1 %in% names_2)
This will return the index of selected strings.
Upvotes: 1
Reputation: 308
If you want to to get a logical vector, you could use:
is.element(names_1, names_2)
If you want to get the elements, which are the same, you could use:
intersect(names_1, names_2)
Upvotes: 1