Chapter 2 R Basics

Throughout this book, we are conscious of the balance between theory and practice. For example, some learners may prefer to get all definitions laid out before they are shown an example making use of the new concepts. Others, however, would much rather see piecemealed sections of practical examples and explanations. We strike a balance between these two approaches that works well for most people in our audience.

This means that sometimes we will show you an example that may use words that have not been formally introduced yet. For example, we start this chapter with data import - as R is nothing without data. But doing so, we have to use the word “argument” that is only defined two sections later (in 2.3 “Objects and functions”). A few similar instances arise around statistical concepts in the Data Analysis part of the book. You will come across sentences along the lines of “this concept will be explained further or become clearer in the next section/chapter”. Trust us and just go with it.

The aim of this chapter is to familiarise you with how R works. We will read in data and start basic manipulations. You may want to skip parts of this chapter if you already:

  • have found the Import Dataset interface
  • know what numbers, characters, factors, and dates look like in R
  • are familiar with the terminology around objects, functions, arguments
  • have used the pipe: %>%
  • know how to filter data with operators such as ==, >, <, &, |
  • know how to handle NAs, and why they can behave weirdly in a filter
  • have used mutate(), c(), paste(), if_else(), and the joins