typestar

Joins in R

The six joins, and what each one does to unmatched rows.

library(dplyr)

runs <- tibble(lang = c("r", "python", "css"), tpm = c(96, 104, 70))
tours <- tibble(lang = c("r", "python", "go"), tours = c(4L, 13L, 6L))

print(inner_join(runs, tours, by = "lang"))
print(left_join(runs, tours, by = "lang"))
print(full_join(runs, tours, by = "lang"))
print(anti_join(runs, tours, by = "lang"))
print(semi_join(runs, tours, by = "lang"))
print(nrow(right_join(runs, tours, by = "lang")))

How it works

  1. left_join keeps every left row, filling with NA.
  2. anti_join keeps left rows with no match, which finds gaps.
  3. semi_join filters without adding the right-hand columns.

Keywords and builtins used here

The run, in numbers

Lines
11
Characters to type
422
Tokens
149
Three-star pace
105 tpm

At the three-star pace of 105 tokens a minute, this run takes about 85 seconds.

Type this snippet

Step 1 of 4 in Joining, step 21 of 27 in dplyr.

← Previous Next →