Vectors
Here, we will learn what vectors are in R and how to create them.
A Vector is a basic data structure in R. It contains elements of the same type at each index. The data types can be
- Logical
- Integer
- Numeric
- Character
- Complex
Creating Vectors
The keyword vector()
is used to create a vector of a fixed type and fixed length.
Press + to interact
R
vector ("numeric", 5) # numeric vector with O at every indexvector ("complex", 5) # complex vector with O+0i at every indexvector ("logical", 5) # logical vector with FALSE at every indexvector ("character", 5) # character vector with "" at every index
Using this method every index will now have a value of zero, FALSE, null string or something equivalent to nothing for the specified data type. ...