Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (7.3k 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

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

Related questions

0 votes
1 answer
0 votes
3 answers
asked Jul 19, 2019 in R Programming by Ajinkya757 (5.3k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...