How does '|' work Does the operator work in R?

I am trying to understand the operator |in R. Why

a = 2
a == 3 | 4

return TRUEin R?

a == 3 

and

a == 4

each returns FALSE, so why does the second row return TRUE?

+4
source share
3 answers

See help(Syntax)- ==has a higher priority than |.

So:

R> a <- 2
R> a == 3 | 4
R> TRUE
R> a == (3 | 4)
R> FALSE
+7
source
a == 3 | 4 

Facilities:

Is (equal to 3) or (4)?

Coincidentally, 4 evaluates to TRUE when forced to boolean.

+1
source

:

`|`(a == 3, 4)
`==`(a, 3)
as.logical(2) # TRUE
as.logical(3) # TRUE
as.logical(4) # TRUE

, , a == 3 ; TRUE == TRUE, TRUE. or TRUE 4 TRUE.

+1

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


All Articles