0

In my dataset, I have a categorical variable Race with three values (1,2,3), but I'd like to select only values 1 and 2. I get different results using the %in% operator and == operator. I'm confused which one is correct and what actually these two operators do (i.e., their difference). Example code:

dfData1 <- dfData1 %>% filter(race %in% c(1,2))
dfData2 <- dfData2 %>% filter(race==c(1,2))

I appreciate your help.

abenol
  • 89
  • 9
  • 3
    `%in%` is correct in your case. See the linked post for their difference. – Ronak Shah Aug 26 '23 at 02:44
  • @RonakShah Thanks for the explanation link. I checked by example and %in% is correct, I was looking for explanation, which you provided. – abenol Aug 26 '23 at 04:00

0 Answers0