2) R Vectors
📖 Lecture
In this unit we describe data types and their implementation as vectors (the most fundamental data object in R). We’ll focus on important concepts like:
main data types (“atomic types” in R): logical, integer, real (or double), 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)
🎯 Objectives
At the end of this week you will be able to:
- Describe 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
https://www.gastonsanchez.com/R-coding-basics/1-01-vectors-intro.html
https://www.gastonsanchez.com/R-coding-basics/1-02-vectors-properties.html
https://www.gastonsanchez.com/R-coding-basics/1-03-vectors-creation.html
a href=“https://www.gastonsanchez.com/R-coding-basics/1-04-vectors-concepts.html” target=“_blank”>https://www.gastonsanchez.com/R-coding-basics/1-04-vectors-concepts.html
🔬 Lab
You’ll practice creating and manipulating vectors in R, and learning about the concepts described above.