liveBook · Manning

Left outer join

As explained in Statistics Slam Dunk

A left join is a tabular merge that retains all rows from one input and attaches matching values from a second input.

A left outer join merges two tables by matching key columns. It keeps every row from the left table and adds matching columns from the right table. When no match exists, the left-side row remains while the attached right-side values are missing. section 14.2.5 section 4.5.4

Use a left join when the left table defines the observations you must preserve:

  • Prepare compatible key columns, renaming duplicate variables when necessary. section 6.3.2
  • Call dplyr::left_join(left_table, right_table, by = ...) with one or more matching keys. section 6.3.2 section 12.7.1
  • Inspect dimensions and columns afterward to verify that rows were preserved and that the expected fields were added. section 6.3.2 section 12.7.1

Combining NBA game records

Split game data into road and home tables, rename shared keys and side-specific variables, then join on dataset, ID, and date: left_join(road, home, by = c("dataset", "ID", "date")). The result retains all 2,073 road observations and adds matching home-team fields, producing 29 columns before unnecessary duplicates are removed. section 6.3.2

Adding team records to salary inequality data

Join gini6 with records by season_end and team to attach wins, losses, winning percentage, and championship status. The resulting gini_records object retains the 816 rows and gains the record variables for later analysis. section 12.7.1

How Statistics Slam Dunk covers it

How deep it goes
Explains row retention, key matching, column growth, and verification, but does not develop join internals.
Examples
Demonstrates free-agent summaries, road-and-home game records, team salary inequality, and annual scoring averages.
What it assumes
Assumes familiarity with tables, columns, rows, matching variables, and basic dplyr pipelines.
What you can do after
Apply it via dplyr::left_join() to combine related tables while preserving the left table's observations.
How it connects
Connects data frames with grouping, summarization, renaming, filtering, factor variables, and other join types.

Also explained in

Compare how 6 books explain left outer join →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Statistics Slam Dunk. The section links point to the parts of the book it draws on.