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

According to the R language definition, the difference between & and && (correspondingly | and ||) is that the former is vectorized while the latter is not.

According to the help text, I read the difference akin to the difference between an "And" and "AndAlso" (correspondingly "Or" and "OrElse")... Meaning: That not all evaluations if they don't have to be (i.e. A or B or C is always true if A is true, so stop evaluating if A is true)

Could someone shed light here? Also, is there an AndAlso and OrElse in R?

1 Answer

0 votes
by (24.7k points)

The boolean operator & and | evaluate each element in a vector and return a vector.

For example:

x <- c (FALSE, TRUE,3,0)

y <- c (FALSE, TRUE, FALSE, TRUE)

x&y

x|y

Output:

[1] FALSE  TRUE FALSE FALSE

[1] FALSE  TRUE  TRUE  TRUE

While the boolean operators && and || evaluate only the first element of each vector and not evaluate the second element if the first element of each vector is enough to determine the value of the expression.

For example:

x <- c (FALSE, TRUE,3,0)

y <- c (FALSE, TRUE, FALSE, TRUE)

x&&y

x||y

Output

> x&&y

[1] FALSE

> x||y

[1] FALSE

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


Categories

...