2) Vectors and Factors

📖 Vectors and Factors

In this module we describe data types and their implementation in R objects like vectors and their cousins factors. We’ll focus on important concepts like:

  • vectors and their data types (e.g. logical, integer, double or real, and character).

  • creation of vectors: various ways and functions to create vectors.

  • implicit coercion rules: what R does when you combine values of different data types.

  • vectorization: when R applies calculations or operations to all the elements of a vector (element-wise).

  • recycling: what R does when you perform a calculation with vectors of different length.

  • subsetting (aka indexing, subscripting, bracket notation)

📰 Slides

02a-vectors-intro.pdf

02b-vectors-subsetting.pdf

02c-factors.pdf

🎯 Objectives

At the end of this week you will be able to:

  • List the four common data types in R, and give examples for them
  • Explain why R vectors are said to be atomic objects
  • Describe and give an example of the implicit coercion rules
  • Describe and give an example of vectorized code
  • Describe and give an example of the recycling rule

📚 Reading