Operator R% in%

In R , I run the following script:

 > 1:6 %in% 0:36 [1] TRUE TRUE TRUE TRUE TRUE TRUE 

This explicitly creates a logical vector. I read the documentation, but I can’t find a statement that returns a scalar based on the result, so 1:6 %in% 0:36 will just return TRUE , with 1:6 %in% 0:36 0:37 %in% 0:36 return FALSE .

Is there one?

+49
r
Apr 30 2018-12-12T00:
source share
1 answer

You can use all

 > all(1:6 %in% 0:36) [1] TRUE > all(1:60 %in% 0:36) [1] FALSE 

Similarly, if you want to check if any of the elements are TRUE, you can use any

 > any(1:6 %in% 0:36) [1] TRUE > any(1:60 %in% 0:36) [1] TRUE > any(50:60 %in% 0:36) [1] FALSE 
+81
Apr 30 2018-12-15T00:
source share



All Articles