Vectors in R
In R, a vector is a collection of elements of the same data type.
When combining different data types in a vector, type coercion occurs.
Type Coercion
Type coercion means that R automatically converts elements to the same data type.
The most flexible data type is chosen to accommodate all elements.
# Example of type coercion element_1 <- 'A' element_2 <- 2 element_3 <- FALSE tmp <- c(element_1, element_2, element_3)
- In this example,
element_1
is a character, forcing all other elements to also become characters in the vectortmp
.