Data science

Stage 1 · Lesson 6 of 7

Joining tables

R for data: the tidyverse

Real data arrives in pieces: orders in one file, customers in another, products in a third. A combines two tables on a key column, like a SQL join. A left join keeps every row of the left table and adds matching columns from the right, filling gaps with missing values when there is no match.

In it is merge; in dplyr it is left_join and its siblings. Always check the row count before and after a join, and tell the tool what relationship you expect, such as many orders to one customer, so it errors when that is false.

Common trapjoining on a key that is not unique in the lookup table: every duplicate multiplies rows and inflates every total that follows, with no error message.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with

  • BookFree
    R for Data Science (2e)

    Wickham, Çetinkaya-Rundel, Grolemund · Beginner

    Free online: the Whole game and Transform chapters teach the tidyverse verbs in the order you need them

Practise

  • Pick one dataset on a topic you care about and repeat every operation in this stage on it

Keep handy

  • Set up projects, the console and Quarto documents properly before you start

Mark this stage as not done?