Reputation:
I have 2 vectors, I want to show logic if elements in vector z are equal to any elements in vector x.
z <- rep(c("AA","AB","AC","AD","AE"), 40)
x <- c("AA","AD","BB")
z == x
I use z == x but the True False values are not correct. Warning shows, "longer object length is not a multiple of shorter object length"
Upvotes: 0
Views: 391
Reputation: 25726
You are looking for %in%
(see ?"%in%"
for details):
z %in% x
head(z %in% x)
# [1] TRUE FALSE FALSE TRUE FALSE TRUE
Upvotes: 3