0

I was trying to extract the following using R. And both of them are giving different results. Could someone tell me the difference between using == and %in%

mfile1 <- subset(data3, COUNTRY_CODE_SHR__C == c("GB","IT","CA"))

mfile <- subset(data3, COUNTRY_CODE_SHR__C %in% c("GB","IT","CA"))

Output is as follows :

mfile1 - 130374 obs of 150 variable
mfile  - 392105 obs of 150 variable
  • 5
    `%in%` is used when you there multiple values to compare `==` is for checking with a single value or when vectors/matrices/dataframes are of the same length/dimensions. You can check the help page `?"%in%"`, `?"=="` – akrun Jul 15 '15 at 06:22
  • 1
    I'm surprised you got any "obs" with the first one. – IRTFM Jul 15 '15 at 06:29
  • @BondedDust `data3` may have a length that is a multiple of 3 – Cath Jul 15 '15 at 07:39

0 Answers0