Vectors in R
Learn the details of the vector data type in the R language.
We'll cover the following...
Vector objects
Vectors act as containers of data elements, forming one-dimensional basic data structures that transform values into a single data type. Vectors can be sorted, filtered, and modified. We can generate vectors using the c()
command.
Vector elements do not always keep the characteristics of their original data type if the vector includes more than one different data type. They converge in a data type that all the elements can be converted into.
The example below illustrates how the disparate data types of individual vector elements can be represented in a mutually compatible format.
# Create vectors using c()myVector <- c('data analysis', 3L, 2i+3, TRUE) # define a vectormyVector1 <- c(3L, TRUE) # define a vectorprint(class(myVector)) # print the class of the variableprint(class(myVector[2])) # Check the class of the second elementprint(class(myVector[3])) # Check the class of the third elementprint(class(myVector1)) # Check the class of the vector
Notice how the data types are automatically converted into a common one in the examples above. The original data types of 2i+3
...