Full join: join two data frames preserving all possible information

Left join: Join two data frames by matching the second (right) data frame to the left (first) such that the structure of the first (left) data frame is preserved

Right join: Join two data frames by matching the first (left) data frame to the right (second) such that the structure of the second (right) data frame is preserved

full_join_data(x, y, by = NULL)

left_join_data(x, y, by = NULL)

right_join_data(x, y, by = NULL)

Arguments

x

Left or first data frame

y

Right or second data frame

by

Name (character) of variable(s) on which to join

Value

Joined (merged) data frame

Examples

d1 <- tbl_data( x = 1:10, y = rnorm(10), z = letters[1:10] ) d2 <- tbl_data( x = sample(1:10, 20, replace = TRUE), y2 = rnorm(20) ) ## left join left_join_data(d1, d2)
#> Joining, by = "x"
#> # A tibble: 21 x 4 #> x y z y2 #> <int> <dbl> <chr> <dbl> #> 1 1 -2.99 a 1.36 #> 2 2 -0.0505 b -0.390 #> 3 2 -0.0505 b -0.417 #> 4 2 -0.0505 b -0.661 #> 5 3 1.30 c NA #> 6 4 -1.35 d 0.652 #> 7 4 -1.35 d -0.405 #> 8 5 -0.950 e 0.854 #> 9 6 1.69 f 0.421 #> 10 6 1.69 f 1.66 #> # … with 11 more rows
## right join right_join_data(d1, d2)
#> Joining, by = "x"
#> # A tibble: 20 x 4 #> x y z y2 #> <int> <dbl> <chr> <dbl> #> 1 7 0.244 g 0.999 #> 2 7 0.244 g -1.09 #> 3 5 -0.950 e 0.854 #> 4 8 -1.39 h -0.627 #> 5 6 1.69 f 0.421 #> 6 9 0.887 i -0.396 #> 7 2 -0.0505 b -0.390 #> 8 10 0.0282 j 0.384 #> 9 6 1.69 f 1.66 #> 10 10 0.0282 j -1.13 #> # … with 10 more rows
## full join full_join_data(d1, d2)
#> Joining, by = "x"
#> # A tibble: 21 x 4 #> x y z y2 #> <int> <dbl> <chr> <dbl> #> 1 1 -2.99 a 1.36 #> 2 2 -0.0505 b -0.390 #> 3 2 -0.0505 b -0.417 #> 4 2 -0.0505 b -0.661 #> 5 3 1.30 c NA #> 6 4 -1.35 d 0.652 #> 7 4 -1.35 d -0.405 #> 8 5 -0.950 e 0.854 #> 9 6 1.69 f 0.421 #> 10 6 1.69 f 1.66 #> # … with 11 more rows