dplyr::right_join()
   get_help() docs


Description

The right_join() function is part of the {dplyr} package, which is part of the {tidyverse}.

The right_join() function merges two relational datasets. Specifically, right_join() retains all rows from the right tibble (data frame) and incorporates columns from the left tibble (data frame): It merges the right into the left. Missing row information becomes NA in the final output, represented in the GIF below by the blank cell.

To use this function, you need to either first load the {dplyr} library, or always use the function with dplyr::right_join() notation.

# Load the library
library(dplyr)
# Or, load the full tidyverse:
library(tidyverse)

# Or, use :: notation
dplyr::right_join()

Conceptual Usage

right_join(left tibble, right tibble)

# or with piping:
left tibble %>%
  right_join(right tibble)

Examples

Consider the following example datasets, These two tibbles have column names name and vore in common. They both contain rows for “Dog”, “Pig”, and “Rabbit”, but first_tibble also contains “Tiger” and second_tibble also contains “Sheep”.

first_tibble
## # A tibble: 4 × 3
##   name   vore  conservation
##   <chr>  <chr> <chr>       
## 1 Dog    carni domesticated
## 2 Pig    omni  domesticated
## 3 Rabbit herbi domesticated
## 4 Tiger  carni en

second_tibble
## # A tibble: 4 × 3
##   name   vore  order       
##   <chr>  <chr> <chr>       
## 1 Dog    carni Carnivora   
## 2 Pig    omni  Artiodactyla
## 3 Rabbit herbi Lagomorpha  
## 4 Sheep  herbi Artiodactyla


# right_join to merge first_tibble into second_tibble
first_tibble %>%
  right_join(second_tibble)
## # A tibble: 4 × 4
##   name   vore  conservation order       
##   <chr>  <chr> <chr>        <chr>       
## 1 Dog    carni domesticated Carnivora   
## 2 Pig    omni  domesticated Artiodactyla
## 3 Rabbit herbi domesticated Lagomorpha  
## 4 Sheep  herbi <NA>         Artiodactyla


# right_join to merge second_tibble into first_tibble
second_tibble %>%
  right_join(first_tibble)
## # A tibble: 4 × 4
##   name   vore  order        conservation
##   <chr>  <chr> <chr>        <chr>       
## 1 Dog    carni Carnivora    domesticated
## 2 Pig    omni  Artiodactyla domesticated
## 3 Rabbit herbi Lagomorpha   domesticated
## 4 Tiger  carni <NA>         en