Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I just had some problems with computing a boolean vector as a result of applying AND to two boolean vectors:

 1234 > x <- c(FALSE, TRUE, FALSE) > y <- c(TRUE, TRUE, FALSE) > x&&y [1] FALSE

As you can see, it’s a nice result, but not what I want.. My hack was the following:

 123456 > # logical AND > as.logical(x*y) [1] FALSE  TRUE FALSE > # logical OR > as.logical(x+y) [1]  TRUE  TRUE FALSE

When Rumpel, my personal R-freak, saw that hack, he just laughed and told me the short version of this hack:

 123456 > # logical AND > x&y [1] FALSE  TRUE FALSE > # logical OR > x|y [1]  TRUE  TRUE FALSE

Nice, isn’t it 😉