...

/

Vectors

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 index
vector ("complex", 5) # complex vector with O+0i at every index
vector ("logical", 5) # logical vector with FALSE at every index
vector ("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. ...