Creating logical vectors
1:100
c(1, 2, 3, 4)
c("abc", "def", "ghi")
c(TRUE, FALSE, TRUE)
View Interactive VersionLogical vectors can only hold the values TRUE
and FALSE
. To create a logical vector with a single value, type out one of the valid values TRUE
or FALSE
. Remember that they must be written with capital letters:
Input
TRUE
Result
[1] TRUE
Similarly to other types of vectors, we can use the concatenate function c()
to create a logical vector of multiple elements:
Input
c(TRUE, FALSE, TRUE, FALSE, TRUE)
Result
[1] TRUE FALSE TRUE FALSE TRUE