Is it a type? Because mydf$participant_ref does not exist.
Assuming it means mydf$event_participant_ref , here are two solutions:
# soln 1
with(data = mydf, expr = {my_participant_ref %in% event_participant_ref})
# soln 2
library(magrittr)
mydf %$% `%in%`(my_participant_ref, event_participant_ref)
But of course it doesn't explain this expected result:
So, please explain how are you getting this result, because I'm getting TRUE for 2 and 4 as well. But I should mention that certainly `%in%` is not only for character vectors.
[In reply to post below]
This is not at all the use case of %in%.
It checks whether the LHS (or each element of LHS) belong to RHS or not. But your problem is not that. You just want to check whether they match or not.
Simply use ==.
with(mydf, my_participant_ref == event_participant_ref)