Chapter 1 Basic R concepts and commands
This chapter lays the foundations for the rest of the book by providing essential background knowledge: First, some terminology on R components, basic distinctions about data shapes and types — that apply not only to R, but also other programming languages — and then some fundamental concepts and commands of base R (R Core Team, 2019).
To learn R, we first need to install some software and introduce some basic terminology for talking about data and code. As this is not an R textbook, we introduce these concepts and commands only briefly and in a playful fashion — by providing examples, interpreting code outputs, and completing a few exercises. Strictly speaking, knowing some R is not a necessary precondition for reading and learning data science with the r4ds textbook (Wickham & Grolemund, 2017). However, having encountered certain terms and various base R commands before is helpful — partly to appreciate later how various tidyverse commands let you solve similar problems in simpler and more transparent ways. Thus, please work through these examples, aim to understand them, and then try to solve the corresponding exercises (in Section 1.8). But if anything seems cryptic or obscure at this point, do not despair or panic. Instead, make a mental note of the task that remained unclear and trust that things will clear up in subsequent chapters. It’s quite likely that you will later learn to solve similar tasks in different ways.