vector_1 = c(4,3,5,1,2)
vector_2 = c(3,1)
output:
[1] FALSE TRUE FALSE TRUE FALSE
how do I get the output just by using basic operators/loops without using the operator %in% or any functions in R?
CodePudding user response:
One way with sapply()
-
sapply(vector_1, function(x) any(x == vector_2))
[1] FALSE TRUE FALSE TRUE FALSE
CodePudding user response:
See match.fun(`%in%`)
match(vector_1,vector_2, nomatch = 0) > 0