Import your data

sports <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-03-29/sports.csv')
## Rows: 132327 Columns: 28
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (8): institution_name, city_txt, state_cd, zip_text, classification_nam...
## dbl (20): year, unitid, classification_code, ef_male_count, ef_female_count,...
## 
## ℹ 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.

Chapter 13

What are primary keys in your data?

sports %>% 
    count(year, unitid, sports) %>% 
    filter(n == 1)
## # A tibble: 132,327 × 4
##     year unitid sports                 n
##    <dbl>  <dbl> <chr>              <int>
##  1  2015 100654 All Track Combined     1
##  2  2015 100654 Baseball               1
##  3  2015 100654 Basketball             1
##  4  2015 100654 Bowling                1
##  5  2015 100654 Football               1
##  6  2015 100654 Golf                   1
##  7  2015 100654 Soccer                 1
##  8  2015 100654 Softball               1
##  9  2015 100654 Tennis                 1
## 10  2015 100654 Volleyball             1
## # … with 132,317 more rows

Can you divide your data into two?

Divide it using dplyr::select in a way the two have a common variable, which you could use to join the two.

sports_half <- sports %>%
    select(year:sector_name) %>%
    head(50)
sports_other_half <- sports %>%
    select(sector_name:sports) %>%
    head(50)

Can you join the two together?

Use tidyr::left_join or other joining functions.

left_join(sports_half, sports_other_half, multiple = "all")
## Joining with `by = join_by(sector_name)`
## # A tibble: 2,500 × 28
##     year unitid instit…¹ city_…² state…³ zip_t…⁴ class…⁵ class…⁶ class…⁷ ef_ma…⁸
##    <dbl>  <dbl> <chr>    <chr>   <chr>   <chr>     <dbl> <chr>   <chr>     <dbl>
##  1  2015 100654 Alabama… Normal  AL      35762         2 NCAA D… <NA>       1923
##  2  2015 100654 Alabama… Normal  AL      35762         2 NCAA D… <NA>       1923
##  3  2015 100654 Alabama… Normal  AL      35762         2 NCAA D… <NA>       1923
##  4  2015 100654 Alabama… Normal  AL      35762         2 NCAA D… <NA>       1923
##  5  2015 100654 Alabama… Normal  AL      35762         2 NCAA D… <NA>       1923
##  6  2015 100654 Alabama… Normal  AL      35762         2 NCAA D… <NA>       1923
##  7  2015 100654 Alabama… Normal  AL      35762         2 NCAA D… <NA>       1923
##  8  2015 100654 Alabama… Normal  AL      35762         2 NCAA D… <NA>       1923
##  9  2015 100654 Alabama… Normal  AL      35762         2 NCAA D… <NA>       1923
## 10  2015 100654 Alabama… Normal  AL      35762         2 NCAA D… <NA>       1923
## # … with 2,490 more rows, 18 more variables: ef_female_count <dbl>,
## #   ef_total_count <dbl>, sector_cd <dbl>, sector_name <chr>, sportscode <dbl>,
## #   partic_men <dbl>, partic_women <dbl>, partic_coed_men <dbl>,
## #   partic_coed_women <dbl>, sum_partic_men <dbl>, sum_partic_women <dbl>,
## #   rev_men <dbl>, rev_women <dbl>, total_rev_menwomen <dbl>, exp_men <dbl>,
## #   exp_women <dbl>, total_exp_menwomen <dbl>, sports <chr>, and abbreviated
## #   variable names ¹​institution_name, ²​city_txt, ³​state_cd, ⁴​zip_text, …