I made a mistake and instead of writing MyData1 %in% c("a", "b")
...I wrote MyData1 == c("a", "b")
...but I'd like to know how and why this doesnt work. Why does the following happen?
> MyData1 <- rep(c("a", "b", "b"), 4)
> MyData1
[1] "a" "b" "b" "a" "b" "b" "a" "b" "b" "a" "b" "b"
> MyData1 == c("a", "b")
[1] TRUE TRUE FALSE FALSE FALSE TRUE TRUE TRUE FALSE FALSE FALSE TRUE
Why is the first result TRUE and the second FALSE? Try:
> MyData1[1] == c("a", "b")
[1] TRUE FALSE
> MyData1[2] == c("a", "b")
[1] FALSE TRUE
> MyData1[1:2] == c("a", "b")
[1] TRUE TRUE
...I'm none the wiser...now I get two items back whether I test 1 or 2 elements of the vector!