Using & in R (e.g. 3 <(5 & 9))

I am trying to learn R and understand how a symbol works &. I understand that this means "and."

When am I trying to 3 < (5 & 4)get it FALSE? I was expecting TRUE. Am I using the &wrong way?

+4
source share
3 answers

In R TRUE, the number 1in your arithmetic expression is evaluated , therefore:

3 < (5 & 4)
3 < TRUE
3 < 1

which is equal FALSE

You can verify that R treats TRUEas the 1following code snippet:

> x <- c(-3:3)
> x
[1] -3 -2 -1  0  1  2  3
> x == TRUE
[1] FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
+6
source

, , , : " 3 5 4?". , 3 < (5 & 4). , R , (5 4), , , 3 TRUE. , - :

(3 < 4) & (3 < 5)

:

all(3 < c(4,5))
+5

Try using:

3 < c(4,5)

Thus, it will be tested for both 4 and 5.

Answer:

TRUE TRUE
+3
source

Source: https://habr.com/ru/post/1598151/


All Articles