Import your data
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.
data_small <- season_goals %>%
slice(1:5) %>%
select(player, total_goals:team)
data_small
## # A tibble: 5 × 7
## player total_goals status yr_start season age team
## <chr> <dbl> <chr> <dbl> <chr> <dbl> <chr>
## 1 Wayne Gretzky 894 Retired 1979 1978-79 18 TOT
## 2 Wayne Gretzky 894 Retired 1979 1978-79 18 INR
## 3 Wayne Gretzky 894 Retired 1979 1978-79 18 EDO
## 4 Wayne Gretzky 894 Retired 1979 1979-80 19 EDM
## 5 Wayne Gretzky 894 Retired 1979 1980-81 20 EDM
Separating and Uniting
Unite two columns
data_united <- data_small %>%
unite(col = "newName", team, season, sep = "/", remove = TRUE)
Separate a column
data_united %>%
separate(col = newName, into = c("team", "season"), sep = "/")
## # A tibble: 5 × 7
## player total_goals status yr_start team season age
## <chr> <dbl> <chr> <dbl> <chr> <chr> <dbl>
## 1 Wayne Gretzky 894 Retired 1979 TOT 1978-79 18
## 2 Wayne Gretzky 894 Retired 1979 INR 1978-79 18
## 3 Wayne Gretzky 894 Retired 1979 EDO 1978-79 18
## 4 Wayne Gretzky 894 Retired 1979 EDM 1979-80 19
## 5 Wayne Gretzky 894 Retired 1979 EDM 1980-81 20
Missing Values