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
left_joinkeeps every left row, filling with NA.anti_joinkeeps left rows with no match, which finds gaps.semi_joinfilters without adding the right-hand columns.
Keywords and builtins used here
anti_joincfull_joininner_joinleft_joinlibrarynrowprintright_joinsemi_jointibble
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.
Step 1 of 4 in Joining, step 21 of 27 in dplyr.