From d5b151c3605d997420131b716677705cc4e10254 Mon Sep 17 00:00:00 2001 From: Mitsuo Shiota <48662507+mitsuoxv@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:24:18 +0900 Subject: [PATCH] Suggest/joins (#1469) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * - better to make code compatible with the figure - better to remove the last row: 1 Max NA - make sure at leaset one employee born before Jan 10, and make output reproducible * Use join_by() --------- Co-authored-by: Mine Çetinkaya-Rundel --- joins.qmd | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/joins.qmd b/joins.qmd index 0f89889..25d0167 100644 --- a/joins.qmd +++ b/joins.qmd @@ -673,7 +673,7 @@ In equi joins the `x` keys and `y` are always equal, so we only need to show one We can request that dplyr keep both keys with `keep = TRUE`, leading to the code below and the re-drawn `inner_join()` in @fig-inner-both. ```{r} -x |> left_join(y, by = "key", keep = TRUE) +x |> inner_join(y, join_by(key == key), keep = TRUE) ``` ```{r} @@ -771,7 +771,7 @@ One small useful technique is to use them to restrict the cross join so that ins ```{r} df <- tibble(id = 1:4, name = c("John", "Simon", "Tracy", "Max")) -df |> left_join(df, join_by(id < id)) +df |> inner_join(df, join_by(id < id)) ``` ### Rolling joins @@ -811,6 +811,7 @@ parties <- tibble( Now imagine that you have a table of employee birthdays: ```{r} +set.seed(123) employees <- tibble( name = sample(babynames::babynames$name, 100), birthday = ymd("2022-01-01") + (sample(365, 100, replace = TRUE) - 1)