0 votes
1 view
in R Programming by (5.3k points)

In R, I have been running the following script:

> 1:6 %in% 0:36

[1] TRUE TRUE TRUE TRUE TRUE TRUE

Which is clearly producing a logical vector. I have read the documentation but can't seem to find an operator that would return a scalar based on the result, such that 1:6 %in% 0:36 would simply return TRUE while having 0:37 %in% 0:36 return FALSE.

Does one exist?

1 Answer

0 votes
by (25.3k points)

To get the desired output, you can use the all() function from the base package as follows:

> all(1:6 %in% 0:36)

[1] TRUE

> all(1:60 %in% 0:36)

[1] FALSE

To check if any of the element is TRUE, you can use the any() function from the base R as follows:

> any(1:60 %in% 0:36)

[1] TRUE

> any(50:60 %in% 0:36)

[1] FALSE

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...