<- c(FALSE, TRUE)
v1 = c(FALSE, TRUE)
v1 <- c(F, T) v1
Vector Basics
Reading Assignments
Make sure to read the following sections in the textbook: R Coding Basics, https://www.gastonsanchez.com/R-coding-basics/
Vector Types: logical, integer, double, character
v1 is a logical vector
v2 is an integer vector
<- c(0L, 1L)
v2 = c(0L, 1L) v2
v3 is a double vector
<- c(0, 1) v3
v4 is a character vector
<- c('0', '1') # Equivalently, v4 <- c("0", "1") v4
Use typeof() function to identify the type
typeof(v1)
#> [1] "logical"
typeof(v2)
#> [1] "integer"
typeof(v3)
#> [1] "double"
typeof(v4)
#> [1] "character"
Use mode() function to identify the type
mode(v1)
#> [1] "logical"
mode(v2) # integer is numeric type
#> [1] "numeric"
mode(v3) # double is numeric type
#> [1] "numeric"
mode(v4)
#> [1] "character"
Recall v2 is an integer vector
is.logical(v2)
#> [1] FALSE
is.character(v2)
#> [1] FALSE
is.integer(v2)
#> [1] TRUE
is.double(v2)
#> [1] FALSE
is.numeric(v2)
#> [1] TRUE