Import your data

data <- 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.
set.seed(123)
data_small <- data %>%
    select(sports, rev_men, rev_women) %>%
    drop_na() %>%
    sample_n(10)

data_small
## # A tibble: 10 × 3
##    sports                  rev_men rev_women
##    <chr>                     <dbl>     <dbl>
##  1 Basketball               126168    116033
##  2 Ice Hockey               297601    212122
##  3 All Track Combined       456892    579246
##  4 Bowling                  143869    133280
##  5 Track and Field, Indoor   31196     15598
##  6 Soccer                   256777    332175
##  7 Basketball               436608    420927
##  8 Ice Hockey               170751    161683
##  9 Golf                     688571    749251
## 10 Basketball                71200     29461

Pivoting

long to wide form

data_small_wide <- data_small %>%
    pivot_wider(names_from = sports, values_from = rev_men)

wide to long form

Separating and Uniting

Unite two columns

data_united <- data_small %>%
    
    unite(col = "newName", sports:rev_men, sep = "/", remove = TRUE)

Separate a column

data_united %>%
    
    separate(col= newName, into= c("sports", "rev_men"), sep= "/")
## # A tibble: 10 × 3
##    sports                  rev_men rev_women
##    <chr>                   <chr>       <dbl>
##  1 Basketball              126168     116033
##  2 Ice Hockey              297601     212122
##  3 All Track Combined      456892     579246
##  4 Bowling                 143869     133280
##  5 Track and Field, Indoor 31196       15598
##  6 Soccer                  256777     332175
##  7 Basketball              436608     420927
##  8 Ice Hockey              170751     161683
##  9 Golf                    688571     749251
## 10 Basketball              71200       29461

Missing Values