Chapter 2 R Objects (I): Basic Vectors
Learning Objectives
After completing this chapter, you will be able to:
- Create and manipulate numeric, character, and logical vectors
- Understand the type coercion rules R uses to convert between vector types
- Use subsetting and modifying techniques to precisely control vector values
Object assignment (Chapter 1.3) gave you the power to name and reuse values. The next step is to understand what those named values actually are. In R, almost every data structure you meet ultimately reduces to an atomic vector: a one-dimensional sequence of values that all share the same underlying type.
Chapter 2 is about mastering the basic building blocks. You will learn how to create vectors from scratch, apply R’s vectorized operations confidently, and subset them to extract specific values. Along the way you will discover how R stores different kinds of information—numbers, text, and logical flags—and how to keep those types straight as you analyze data. For more complex operations on vectors like sorting, statistics, set operations, and dates, we will cover them in Chapter 3.
At a glance – Chapter ROADMAP
Section 2.1. Numeric vectors: Create numeric sequences and perform arithmetic in a vectorized way.
Section 2.2. Character vectors: Build strings and work with textual data.
Section 2.3. Logical vectors: Record yes/no information.
Section 2.4. Type coercion: Predict how R converts between vector types when they meet in the same object.
Section 2.5. Vector subsetting: Subset and modify values precisely.