full_join()
The full join includes all rows from the x
dataset or the y
dataset and takes in the following arguments. In your case, it would include all the rows from dt4.1
or dt4.2
.
The full_join()
takes in the following arguments:
full_join(x dataset, y dataset, by = c("character vector of variables to join by"))
full_join()
Example:
Here are two datasets I made up: my_pets
and friends_pets
my_pets
#> # A tibble: 6 x 3
#> pet_name species met_friends_pets
#> <chr> <chr> <chr>
#> 1 Smoochie cat yes
#> 2 Salem cat yes
#> 3 Samson cat no
#> 4 Brutus cat no
#> 5 Gus cat no
#> 6 Sage dog yes
friends_pets
#> # A tibble: 3 x 3
#> pet_name species met_friends_pets
#> <chr> <chr> <chr>
#> 1 Nala dog yes
#> 2 Frankie dog yes
#> 3 Kila dog no
Created on 2023-10-10 by the reprex package (v2.0.1)
Now I will join these datasets together by the column they have in common, which is met_friends_pets
, by using full_join()
:
full_join(my_pets,friends_pets, met_friends_pets = "yes")
#> Joining, by = c("pet_name", "species", "met_friends_pets")
#> # A tibble: 9 x 3
#> pet_name species met_friends_pets
#> <chr> <chr> <chr>
#> 1 Smoochie cat yes
#> 2 Salem cat yes
#> 3 Samson cat no
#> 4 Brutus cat no
#> 5 Gus cat no
#> 6 Sage dog yes
#> 7 Nala dog yes
#> 8 Frankie dog yes
#> 9 Kila dog no
Created on 2023-10-10 by the reprex package (v2.0.1)
The new table includes every row from each dataset. Notice I specified in the full_join()
argument to join based on met_friends_pets = "yes"
. Not every pet has a "yes" in the met_friends_pets
column, but they are still included in the full join.