Usually, if I want to subset a dataframe conditioning of some values a variable I'm using subset and %in%:
x <- data.frame(u=1:10,v=LETTERS[1:10])
x
subset(x, v %in% c("A","D"))
Now, I found out that also == gives the same result:
subset(x, v == c("A","D"))
I'm just wondering if they are identically or if there is a reason to prefere one over the other. Thanks for help.
Edit (@MrFlick): This question asks not the same as this here which asks how to not include several values: (!x %in% c('a','b'))
. I asked why I got the same if I use ==
or %in%
.