Import your data
videogames <- read_csv("../00_data/video_games.csv")
## Rows: 26688 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): game, release_date, owners, developer, publisher
## dbl (5): number, price, average_playtime, median_playtime, metascore
##
## ℹ 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.
videogames
## # A tibble: 26,688 × 10
## number game release_date price owners developer publisher average_playtime
## <dbl> <chr> <chr> <dbl> <chr> <chr> <chr> <dbl>
## 1 1 Half-L… Nov 16, 2004 9.99 10,00… Valve Valve 110
## 2 3 Counte… Nov 1, 2004 9.99 10,00… Valve Valve 236
## 3 21 Counte… Mar 1, 2004 9.99 10,00… Valve Valve 10
## 4 47 Half-L… Nov 1, 2004 4.99 5,000… Valve Valve 0
## 5 36 Half-L… Jun 1, 2004 9.99 2,000… Valve Valve 0
## 6 52 CS2D Dec 24, 2004 NA 1,000… Unreal S… Unreal S… 16
## 7 2 Unreal… Mar 16, 2004 15.0 500,0… Epic Gam… Epic Gam… 0
## 8 4 DOOM 3 Aug 3, 2004 4.99 500,0… id Softw… id Softw… 0
## 9 14 Beyond… Apr 27, 2004 5.99 500,0… Larian S… Larian S… 0
## 10 40 Hitman… Apr 20, 2004 8.99 500,0… Io-Inter… Io-Inter… 0
## # ℹ 26,678 more rows
## # ℹ 2 more variables: median_playtime <dbl>, metascore <dbl>
set.seed(1234)
videogames_short <- videogames %>%
filter(!is.na(metascore)) %>%
select(game, developer, metascore) %>%
sample_n(10)
videogames_short
## # A tibble: 10 × 3
## game developer metascore
## <chr> <chr> <dbl>
## 1 Baldur's Gate: Enhanced Edition Beamdog 78
## 2 Sanctum Coffee Stain Studios 70
## 3 BELOW Capybara Games 67
## 4 Gemini Wars Camel101 LLC 53
## 5 Restaurant Empire II Enlight Software Limited 64
## 6 Breached Drama Drifters 54
## 7 Sea Dogs Akella 71
## 8 Phantom Breaker: Battle Grounds MAGES. Inc. 64
## 9 GIGA WRECKER GAME FREAK inc. 75
## 10 Ittle Dew Ludosity 67
Pivoting
long to wide
vg_wide <- videogames_short %>%
pivot_wider(names_from = developer, values_from = metascore)
vg_wide
## # A tibble: 10 × 11
## game Beamdog `Coffee Stain Studios` `Capybara Games` `Camel101 LLC`
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Baldur's Gate… 78 NA NA NA
## 2 Sanctum NA 70 NA NA
## 3 BELOW NA NA 67 NA
## 4 Gemini Wars NA NA NA 53
## 5 Restaurant Em… NA NA NA NA
## 6 Breached NA NA NA NA
## 7 Sea Dogs NA NA NA NA
## 8 Phantom Break… NA NA NA NA
## 9 GIGA WRECKER NA NA NA NA
## 10 Ittle Dew NA NA NA NA
## # ℹ 6 more variables: `Enlight Software Limited` <dbl>, `Drama Drifters` <dbl>,
## # Akella <dbl>, `MAGES. Inc.` <dbl>, `GAME FREAK inc.` <dbl>, Ludosity <dbl>
wide to long
vg_wide %>%
pivot_longer(c(`Beamdog`:`Ludosity`), names_to = "developer", values_to = "metascore", values_drop_na = TRUE)
## # A tibble: 10 × 3
## game developer metascore
## <chr> <chr> <dbl>
## 1 Baldur's Gate: Enhanced Edition Beamdog 78
## 2 Sanctum Coffee Stain Studios 70
## 3 BELOW Capybara Games 67
## 4 Gemini Wars Camel101 LLC 53
## 5 Restaurant Empire II Enlight Software Limited 64
## 6 Breached Drama Drifters 54
## 7 Sea Dogs Akella 71
## 8 Phantom Breaker: Battle Grounds MAGES. Inc. 64
## 9 GIGA WRECKER GAME FREAK inc. 75
## 10 Ittle Dew Ludosity 67
Separating and Uniting
Unite Two Columns
vg_unite <- videogames_short %>%
unite(col = "game/dev", game:developer, sep = "/")
Separate a Column
vg_unite %>%
separate(col = `game/dev`, into = c("game", "developer"), sep = "/")
## # A tibble: 10 × 3
## game developer metascore
## <chr> <chr> <dbl>
## 1 Baldur's Gate: Enhanced Edition Beamdog 78
## 2 Sanctum Coffee Stain Studios 70
## 3 BELOW Capybara Games 67
## 4 Gemini Wars Camel101 LLC 53
## 5 Restaurant Empire II Enlight Software Limited 64
## 6 Breached Drama Drifters 54
## 7 Sea Dogs Akella 71
## 8 Phantom Breaker: Battle Grounds MAGES. Inc. 64
## 9 GIGA WRECKER GAME FREAK inc. 75
## 10 Ittle Dew Ludosity 67