Chapter 2 R basics

Throughout this book, we are conscious of the balance between theory and practice. Some learners may prefer to see all definitions laid out before being shown an example of a new concept. Others, would rather see practical examples and explanations build up to a full understanding over time. We strike a balance between these two approaches that works well for most people in the audience.

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 - R is nothing without data.

In so doing, we have to use the word “argument”, which 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 become clearer in the next section”. 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 missing data (NAs), and why they can behave weirdly in a filter;
  • have used mutate(), c(), paste(), if_else(), and the joins.