Reputation: 3125
Why is it that:
> 'c' %in% c('c', 'b')
[1] TRUE
But
> all('c' %in% c('c', 'b'))
[1] TRUE
Shouldn't this be false?
According to the documentation:
Are All Values True?
Description
Given a set of logical vectors, are all of the values true?
I gave it a set of logical vectors, and NOT ALL of the values are true.r
Upvotes: 0
Views: 3573
Reputation: 6306
CASE 1:
> 1:4 %in% 1:10
[1] TRUE TRUE TRUE TRUE
In this case logical vector is returned. Since each element of 1:4 is present in 1:10 we are getting TRUE for all elements.
CASE 2:
> 1:11 %in% 1:10
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[11] FALSE
We are getting TRUE for all except 11 as 11 is not in 1:10
CASE 3:
all(1:4 %in% 1:10)
[1] TRUE
If we use all() it will return either TRUE or FALSE.It will tell whether all elements of 1:4 are present in 1:10 or not.
CASE 4:
> all(1:11 %in% 1:10)
[1] FALSE
Since 11 is not in 1:10 thats why we are getting FALSE.
Now you can solve your problem very easily. all() return TRUE if all conditions are TRUE otherwise return FALSE.
Upvotes: 3