Vectors

Learning Outcomes

By the end of this tutorial, you will be able to:

  • Describe the characteristics of atomic vectors.
  • Describe the six atomic vector modes (logical, integer, double, character, complex, raw).
  • Generate new atomic vectors using various functions.
  • Perform element-wise arithmetic and logical operations on atomic vectors.
  • Select and modify elements in a vector.
  • Explain “recycling”, and describe how it works when manipulating vectors.

Vectors are the simplest data structure in R: scalars don’t exist in R. A vector is simply an ordered collection of values with the same type (e.g., all numbers, all character strings, all boolean values).

Whenever you’re working with R, you’re almost always using vectors, whether you realize it or not. Vectors are very simple objects, but the more complex objects you’ll encounter later (matrices, lists, data frames, and factors) are all built from vectors. Getting comfortable with vectors now will certainly pay off as you progress in your R journey.

Back to top