auto S## ---- echo = FALSE, message = FALSE------------------------------------------- knitr::opts_chunk$set(collapse = T, comment = "#>") options(tibble.print_min = 5) library(dplyr) ## ---- warning = FALSE--------------------------------------------------------- library(nycflights13) # Drop unimportant variables so it's easier to understand the join results. flights2 <- flights %>% select(year:day, hour, origin, dest, tailnum, carrier) flights2 %>% left_join(airlines) ## ----------------------------------------------------------------------------- flights2 %>% left_join(weather) ## ----------------------------------------------------------------------------- flights2 %>% left_join(planes, by = "tailnum") ## ----------------------------------------------------------------------------- flights2 %>% left_join(airports, c("dest" = "faa")) flights2 %>% left_join(airports, c("origin" = "faa")) ## ----------------------------------------------------------------------------- df1 <- tibble(x = c(1, 2), y = 2:1) df2 <- tibble(x = c(3, 1), a = 10, b = "a") ## ----------------------------------------------------------------------------- df1 %>% inner_join(df2) %>% knitr::kable() ## ----------------------------------------------------------------------------- df1 %>% left_join(df2) ## ----------------------------------------------------------------------------- df1 %>% right_join(df2) df2 %>% left_join(df1) ## ----------------------------------------------------------------------------- df1 %>% full_join(df2) ## ----------------------------------------------------------------------------- df1 <- tibble(x = c(1, 1, 2), y = 1:3) df2 <- tibble(x = c(1, 1, 2), z = c("a", "b", "a")) df1 %>% left_join(df2) ## ----------------------------------------------------------------------------- library("nycflights13") flights %>% anti_join(planes, by = "tailnum") %>% count(tailnum, sort = TRUE) ## ----------------------------------------------------------------------------- df1 <- tibble(x = c(1, 1, 3, 4), y = 1:4) df2 <- tibble(x = c(1, 1, 2), z = c("a", "b", "a")) # Four rows to start with: df1 %>% nrow() # And we get four rows after the join df1 %>% inner_join(df2, by = "x") %>% nrow() # But only two rows actually match df1 %>% semi_join(df2, by = "x") %>% nrow() ## ----------------------------------------------------------------------------- (df1 <- tibble(x = 1:2, y = c(1L, 1L))) (df2 <- tibble(x = 1:2, y = 1:2)) ## ----------------------------------------------------------------------------- intersect(df1, df2) # Note that we get 3 rows, not 4 union(df1, df2) setdiff(df1, df2) setdiff(df2, df1) 5ˆl–äY>”TÂXÔÊ€~à›¸)‹Fÿ�þ^eõ›•‘€:”þÄ ƒ@ßÃÂÁ9# created by tools/loadICU.tcl -- do not edit namespace eval ::tcl::clock { ::msgcat::mcset mk DAYS_OF_WEEK_ABBREV [list \ "\u043d\u0435\u0434."\ "\u043f\u043e\u043d."\ "\u0432\u0442."\ "\u0441\u0440\u0435."\ "\u0447\u0435\u0442."\ "\u043f\u0435\u0442."\ "\u0441\u0430\u0431."] ::msgcat::mcset mk DAYS_OF_WEEK_FULL [list \ "\u043d\u0435\u0434\u0435\u043b\u0430"\ "\u043f\u043e\u043d\u0435\u0434\u0435\u043b\u043d\u0438\u043a"\ "\u0432\u0442\u043e\u0440\u043d\u0438\u043a"\ "\u0441\u0440\u0435\u0434\u0430"\ "\u0447\u0435\u0442\u0432\u0440\u0442\u043e\u043a"\ "\u043f\u0435\u0442\u043e\u043a"\ "\u0441\u0430\u0431\u043e\u0442\u0430"] ::msgcat::mcset mk MONTHS_ABBREV [list \ "\u0458\u0430\u043d."\ "\u0444\u0435\u0432."\ "\u043c\u0430\u0440."\ "\u0430\u043f\u0440."\ "\u043c\u0430\u0458."\ "\u0458\u0443\u043d."\ "\u0458\u0443\u043b."\ "\u0430\u0432\u0433."\ "\u0441\u0435\u043f\u0442."\ "\u043e\u043a\u0442."\ "\u043d\u043e\u0435\u043c."\ "\u0434\u0435\u043a\u0435\u043c."\ ""] ::msgcat::mcset mk MONTHS_FULL [list \ "\u0458\u0430\u043d\u0443\u0430\u0440\u0438"\ "\u0444\u0435\u0432\u0440\u0443\u0430\u0440\u0438"\