typestar

dplyr joins in R

Combining tibbles with explicit join verbs.

library(dplyr)

people <- tibble(id = 1:3, name = c("ada", "grace", "kay"))
scores <- tibble(id = c(1, 2, 4), score = c(95, 88, 70))

inner <- inner_join(people, scores, by = "id")
left <- left_join(people, scores, by = "id")
full <- full_join(people, scores, by = "id")

unmatched <- anti_join(people, scores, by = "id")
matched <- semi_join(people, scores, by = "id")
stacked <- bind_rows(people, tibble(id = 4, name = "alan"))

How it works

  1. inner_join, left_join, and full_join match on a key.
  2. anti_join and semi_join filter by match instead.
  3. bind_rows stacks tables with matching columns.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
429
Tokens
137
Three-star pace
105 tpm

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

Type this snippet

Step 4 of 4 in Joining, step 24 of 27 in dplyr.

← Previous Next →