1. Import your data

Import two related datasets from TidyTuesday Project.

library(readr)

monthly_losses_data <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2026/2026-03-17/monthly_losses_data.csv')
## Rows: 2808 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (3): species, geo_group, region
## dbl  (5): losses, dead, discarded, escaped, other
## date (1): date
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
monthly_mortality_data <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2026/2026-03-17/monthly_mortality_data.csv')
## Rows: 1788 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (3): species, geo_group, region
## dbl  (3): median, q1, q3
## date (1): date
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

My data for this project does have two seperate data files, although they do not necessarily make sense to use for joining practice. While the functions used are successfully applied, it does not make a comprehensible comparison.

2. Make data small

Describe the two datasets:

Data 1 = Monthly Losses

Data 2 = Monthly Mortality

set.seed(1234)
monthly_losses_data_small <- monthly_losses_data %>% select(species, date, losses) %>% sample_n(10)
monthly_mortality_data_small <- monthly_mortality_data %>% select(species, date, median) %>% sample_n(10)

monthly_losses_data_small
## # A tibble: 10 × 3
##    species      date        losses
##    <chr>        <date>       <dbl>
##  1 salmon       2023-08-01  504282
##  2 salmon       2022-04-01  242596
##  3 rainbowtrout 2025-05-01     127
##  4 salmon       2023-05-01     534
##  5 salmon       2021-06-01  355736
##  6 rainbowtrout 2022-07-01       0
##  7 rainbowtrout 2025-10-01     995
##  8 salmon       2025-11-01 1699564
##  9 rainbowtrout 2023-09-01       0
## 10 salmon       2023-12-01       0
monthly_mortality_data_small
## # A tibble: 10 × 3
##    species      date       median
##    <chr>        <date>      <dbl>
##  1 salmon       2022-08-01   0.37
##  2 rainbowtrout 2025-06-01   0.43
##  3 salmon       2024-02-01   1.07
##  4 rainbowtrout 2024-04-01   0.31
##  5 salmon       2020-10-01   1.09
##  6 rainbowtrout 2020-04-01   0.51
##  7 salmon       2023-05-01   0.54
##  8 salmon       2024-12-01   0.57
##  9 salmon       2021-12-01   0.62
## 10 salmon       2022-04-01   0.44

3. inner_join

Describe the resulting data:

How is it different from the original two datasets? This join only uses rows that have matching column values.

inner_join(monthly_losses_data_small, monthly_mortality_data_small)
## Joining with `by = join_by(species, date)`
## # A tibble: 2 × 4
##   species date       losses median
##   <chr>   <date>      <dbl>  <dbl>
## 1 salmon  2022-04-01 242596   0.44
## 2 salmon  2023-05-01    534   0.54

4. left_join

Describe the resulting data:

How is it different from the original two datasets? This keeps the values from both datasets and adds matching data from the right dataset to the left dataset.

left_join(monthly_losses_data_small, monthly_mortality_data_small)
## Joining with `by = join_by(species, date)`
## # A tibble: 10 × 4
##    species      date        losses median
##    <chr>        <date>       <dbl>  <dbl>
##  1 salmon       2023-08-01  504282  NA   
##  2 salmon       2022-04-01  242596   0.44
##  3 rainbowtrout 2025-05-01     127  NA   
##  4 salmon       2023-05-01     534   0.54
##  5 salmon       2021-06-01  355736  NA   
##  6 rainbowtrout 2022-07-01       0  NA   
##  7 rainbowtrout 2025-10-01     995  NA   
##  8 salmon       2025-11-01 1699564  NA   
##  9 rainbowtrout 2023-09-01       0  NA   
## 10 salmon       2023-12-01       0  NA

5. right_join

Describe the resulting data:

How is it different from the original two datasets? This does the same as the left_join function, however it adds the data from the left into the right dataset instead.

right_join(monthly_losses_data_small, monthly_mortality_data_small)
## Joining with `by = join_by(species, date)`
## # A tibble: 10 × 4
##    species      date       losses median
##    <chr>        <date>      <dbl>  <dbl>
##  1 salmon       2022-04-01 242596   0.44
##  2 salmon       2023-05-01    534   0.54
##  3 salmon       2022-08-01     NA   0.37
##  4 rainbowtrout 2025-06-01     NA   0.43
##  5 salmon       2024-02-01     NA   1.07
##  6 rainbowtrout 2024-04-01     NA   0.31
##  7 salmon       2020-10-01     NA   1.09
##  8 rainbowtrout 2020-04-01     NA   0.51
##  9 salmon       2024-12-01     NA   0.57
## 10 salmon       2021-12-01     NA   0.62

6. full_join

Describe the resulting data:

How is it different from the original two datasets? Full join combines all columns from both datasets and matches them up when possible.

full_join(monthly_losses_data_small, monthly_mortality_data_small)
## Joining with `by = join_by(species, date)`
## # A tibble: 18 × 4
##    species      date        losses median
##    <chr>        <date>       <dbl>  <dbl>
##  1 salmon       2023-08-01  504282  NA   
##  2 salmon       2022-04-01  242596   0.44
##  3 rainbowtrout 2025-05-01     127  NA   
##  4 salmon       2023-05-01     534   0.54
##  5 salmon       2021-06-01  355736  NA   
##  6 rainbowtrout 2022-07-01       0  NA   
##  7 rainbowtrout 2025-10-01     995  NA   
##  8 salmon       2025-11-01 1699564  NA   
##  9 rainbowtrout 2023-09-01       0  NA   
## 10 salmon       2023-12-01       0  NA   
## 11 salmon       2022-08-01      NA   0.37
## 12 rainbowtrout 2025-06-01      NA   0.43
## 13 salmon       2024-02-01      NA   1.07
## 14 rainbowtrout 2024-04-01      NA   0.31
## 15 salmon       2020-10-01      NA   1.09
## 16 rainbowtrout 2020-04-01      NA   0.51
## 17 salmon       2024-12-01      NA   0.57
## 18 salmon       2021-12-01      NA   0.62

7. semi_join

Describe the resulting data:

How is it different from the original two datasets? This function does not add any columns, it only filters what matches in both and applies it to the left dataset.

semi_join(monthly_losses_data_small, monthly_mortality_data_small)
## Joining with `by = join_by(species, date)`
## # A tibble: 2 × 3
##   species date       losses
##   <chr>   <date>      <dbl>
## 1 salmon  2022-04-01 242596
## 2 salmon  2023-05-01    534

8. anti_join

Describe the resulting data:

How is it different from the original two datasets? This function only keeps rows that do not have a match in the right dataset and filters them from the left.

anti_join(monthly_losses_data_small, monthly_mortality_data_small)
## Joining with `by = join_by(species, date)`
## # A tibble: 8 × 3
##   species      date        losses
##   <chr>        <date>       <dbl>
## 1 salmon       2023-08-01  504282
## 2 rainbowtrout 2025-05-01     127
## 3 salmon       2021-06-01  355736
## 4 rainbowtrout 2022-07-01       0
## 5 rainbowtrout 2025-10-01     995
## 6 salmon       2025-11-01 1699564
## 7 rainbowtrout 2023-09-01       0
## 8 salmon       2023-12-01       0