Join two data.tables together
left_join.(x, y, by = NULL, suffix = c(".x", ".y"), ..., keep = FALSE)
A data.frame or data.table
A data.frame or data.table
A character vector of variables to join by. If NULL, the default, the join will do a natural join, using all variables with common names across the two tables.
Append created for duplicated column names when using full_join()
Other parameters passed on to methods
Should the join keys from both x
and y
be preserved in the output?
df1 <- data.table(x = c("a", "a", "b", "c"), y = 1:4)
df2 <- data.table(x = c("a", "b"), z = 5:6)
df1 %>% left_join(df2)
#> # A tidytable: 4 × 3
#> x y z
#> <chr> <int> <int>
#> 1 a 1 5
#> 2 a 2 5
#> 3 b 3 6
#> 4 c 4 NA
df1 %>% inner_join(df2)
#> # A tidytable: 3 × 3
#> x y z
#> <chr> <int> <int>
#> 1 a 1 5
#> 2 a 2 5
#> 3 b 3 6
df1 %>% right_join(df2)
#> # A tidytable: 3 × 3
#> x y z
#> <chr> <int> <int>
#> 1 a 1 5
#> 2 a 2 5
#> 3 b 3 6
df1 %>% full_join(df2)
#> # A tidytable: 4 × 3
#> x y z
#> <chr> <int> <int>
#> 1 a 1 5
#> 2 a 2 5
#> 3 b 3 6
#> 4 c 4 NA
df1 %>% anti_join(df2)
#> # A tidytable: 1 × 2
#> x y
#> <chr> <int>
#> 1 c 4