1. Import your data

Import two related datasets from TidyTuesday Project.

game_goals <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-03/game_goals.csv')
## Rows: 49384 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr   (7): player, age, team, at, opp, location, outcome
## dbl  (17): season, rank, game_num, goals, assists, points, plus_minus, penal...
## 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.
season_goals <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2020/2020-03-03/season_goals.csv')
## Rows: 4810 Columns: 23
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): position, hand, player, years, status, season, team, league, headshot
## dbl (14): rank, total_goals, yr_start, age, season_games, goals, assists, po...
## 
## ℹ 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.

2. Make data small

Describe the two datasets:

Data1: Season Goals

Data 2: Game Goals

set.seed(1972)
season_goals_small <- season_goals %>% select(rank, player, total_goals) %>% sample_n(10)
game_goals_small <- game_goals %>% select(rank, player, goals) %>% sample_n(10)

3. inner_join

Describe the resulting data:

How is it different from the original two datasets? 1 row compared to 10 in original small data sets

season_goals_small %>% inner_join(game_goals_small, by = c("rank"))
## # A tibble: 1 × 5
##    rank player.x    total_goals player.y      goals
##   <dbl> <chr>             <dbl> <chr>         <dbl>
## 1    32 Stan Mikita         541 Wayne Gretzky     0

4. left_join

Describe the resulting data:

How is it different from the original two datasets? 5 columns as opposed to 3. 10 rows

season_goals_small %>% left_join(game_goals_small, by = c("rank"))
## # A tibble: 10 × 5
##     rank player.x         total_goals player.y      goals
##    <dbl> <chr>                  <dbl> <chr>         <dbl>
##  1    49 Brian Bellows            485 <NA>             NA
##  2   160 Ed Olczyk                342 <NA>             NA
##  3   135 Miroslav Satan           363 <NA>             NA
##  4    32 Stan Mikita              541 Wayne Gretzky     0
##  5     4 Brett Hull               741 <NA>             NA
##  6   156 Jonathan Toews           343 <NA>             NA
##  7   237 Mike Fisher              278 <NA>             NA
##  8   230 Dick Duff                283 <NA>             NA
##  9   212 Jason Pominville         293 <NA>             NA
## 10    77 Brian Propp              425 <NA>             NA

5. right_join

Describe the resulting data:

How is it different from the original two datasets? 5 columns as opposed to 3. 10 rows

season_goals_small %>% right_join(game_goals_small, by = c("rank"))
## # A tibble: 10 × 5
##     rank player.x    total_goals player.y         goals
##    <dbl> <chr>             <dbl> <chr>            <dbl>
##  1    32 Stan Mikita         541 Wayne Gretzky        0
##  2    17 <NA>                 NA Alex Ovechkin        0
##  3    24 <NA>                 NA Brendan Shanahan     0
##  4    53 <NA>                 NA Anze Kopitar         0
##  5    70 <NA>                 NA Dino Ciccarelli      0
##  6    27 <NA>                 NA Mark Messier         0
##  7    52 <NA>                 NA Jaromir Jagr         1
##  8    72 <NA>                 NA Patrick Kane         1
##  9    27 <NA>                 NA John Tavares         0
## 10    53 <NA>                 NA Corey Perry          0

6. full_join

Describe the resulting data:

How is it different from the original two datasets? 5 columns as opposed to 3. 19 rows instead of 10

season_goals_small %>% full_join(game_goals_small, by = c("rank"))
## # A tibble: 19 × 5
##     rank player.x         total_goals player.y         goals
##    <dbl> <chr>                  <dbl> <chr>            <dbl>
##  1    49 Brian Bellows            485 <NA>                NA
##  2   160 Ed Olczyk                342 <NA>                NA
##  3   135 Miroslav Satan           363 <NA>                NA
##  4    32 Stan Mikita              541 Wayne Gretzky        0
##  5     4 Brett Hull               741 <NA>                NA
##  6   156 Jonathan Toews           343 <NA>                NA
##  7   237 Mike Fisher              278 <NA>                NA
##  8   230 Dick Duff                283 <NA>                NA
##  9   212 Jason Pominville         293 <NA>                NA
## 10    77 Brian Propp              425 <NA>                NA
## 11    17 <NA>                      NA Alex Ovechkin        0
## 12    24 <NA>                      NA Brendan Shanahan     0
## 13    53 <NA>                      NA Anze Kopitar         0
## 14    70 <NA>                      NA Dino Ciccarelli      0
## 15    27 <NA>                      NA Mark Messier         0
## 16    52 <NA>                      NA Jaromir Jagr         1
## 17    72 <NA>                      NA Patrick Kane         1
## 18    27 <NA>                      NA John Tavares         0
## 19    53 <NA>                      NA Corey Perry          0

7. semi_join

Describe the resulting data:

How is it different from the original two datasets? 3 columns 1 row opposed to 10

season_goals_small %>% semi_join(game_goals_small, by = c("rank"))
## # A tibble: 1 × 3
##    rank player      total_goals
##   <dbl> <chr>             <dbl>
## 1    32 Stan Mikita         541

8. anti_join

Describe the resulting data:

How is it different from the original two datasets? 3 colums 9 rows compared to 10

season_goals_small %>% anti_join(game_goals_small, by = c("rank"))
## # A tibble: 9 × 3
##    rank player           total_goals
##   <dbl> <chr>                  <dbl>
## 1    49 Brian Bellows            485
## 2   160 Ed Olczyk                342
## 3   135 Miroslav Satan           363
## 4     4 Brett Hull               741
## 5   156 Jonathan Toews           343
## 6   237 Mike Fisher              278
## 7   230 Dick Duff                283
## 8   212 Jason Pominville         293
## 9    77 Brian Propp              425