Introduction to Vectors

A vector is a collection of elements of the same kind and the most basic data structure in R. For example, a vector could hold the four numbers 1, 3, 2 and 5. Another vector could be formed with the three text strings "Welcome", "Hi" and "Hello". These different kinds of values (numbers, text) are called data types.

A single value is also treated as a vector - a vector with only one element in it. As we will see throughout the course, this concept makes R very special. We can manipulate vectors and its values through plenty of operations that are provided by R.

One key advantage of vectors is that we can apply an operation (e.g. a multiplication) to all its values at once instead of going through each item individually. This is called vectorization.

Combine values into a vector