Possible Duplicate:
R: subset() logical-and operator for chaining conditions should be & not &&
What is the difference between short (&,|) and long (&&, ||) forms of AND, OR logical operators in R?
For example:
x==0 & y==1x==0 && y==1x==0 | y==1x==0 || y==1I always use the short forms in my code. Does it have any handicaps?
& and | - are element-wise and can be used with vector operations, whereas, || and && always generate single TRUE or FALSE
theck the difference:
> x <- 1:5
> y <- 5:1
> (x > 2) & (y < 3)
[1] FALSE FALSE FALSE TRUE TRUE
> (x > 2) && (y < 3) # here operaand && takes only 1'st elements from logical
# vectors (x>2) and (y<3)
> FALSE
So, && and || are commonly used in if (condition) state_1 else state_2 statements, as
dealing with vectors of length 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With