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
inner_join,left_join, andfull_joinmatch on a key.anti_joinandsemi_joinfilter by match instead.bind_rowsstacks tables with matching columns.
Keywords and builtins used here
anti_joinbind_rowscfull_joininner_joinleft_joinlibrarysemi_jointibble
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.
Step 4 of 4 in Joining, step 24 of 27 in dplyr.