Logical vectors¶
## Comparisons
x <- -3:3
x
[1] -3 -2 -1 0 1 2 3
x == 0
[1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE
x <- -3:3
y <- c(1:3,0,1:3)
x == y
[1] FALSE FALSE FALSE TRUE TRUE TRUE TRUE
## Logical operators
a <- c(TRUE,FALSE,TRUE,FALSE)
b <- c(TRUE,TRUE,FALSE,FALSE)
a & b
[1] TRUE FALSE FALSE FALSE
a | b
[1] TRUE TRUE TRUE FALSE
!a
[1] FALSE TRUE FALSE TRUE
a & !b
[1] FALSE FALSE TRUE FALSE
!(a | b)
[1] FALSE FALSE FALSE TRUE
x <- -3:3
x > 1 & x < -1
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE
x > 1 | x < -1
[1] TRUE TRUE FALSE FALSE FALSE TRUE TRUE
a <- c(TRUE,FALSE,NA,TRUE,FALSE,NA,TRUE,FALSE,NA)
b <- c(TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,NA,NA,NA)
a & b
[1] TRUE FALSE NA FALSE FALSE FALSE NA FALSE NA
a | b
[1] TRUE TRUE TRUE TRUE FALSE NA TRUE NA NA
- R file: logical-vectors.R
- Rmarkdown file: logical-vectors.Rmd
- Jupyter notebook file: logical-vectors.ipynb
- Interactive version of the Jupyter notebook (shuts down after 60s):
- Interactive version of the Jupyter notebook (sign in required):