
Reshape Wide to Long in R - How to Use pivot_longer
Video Game Sales Data: www.kaggle.com/datasets/gregorut/videogamesales
In this video, we use a Kaggle data set that has video game sales data from about 1980-2020. There are 4 columns for sales by region, NA_sales, EU_Sales, JP_Sales, and Other_Sales.
While this may make some sense for viewing the data, keeping all of these columns will limit our ability to work with the data if we're interested in how things vary across different regions.
in order to condense these 4 separate columns into one, we use the pivot_longer function in R (from the tidyr package). This allows us to reshape our data set from wide (with 4 columns) to long (with only one column called "region").
At the end, we cover a basic use case of how having the data in a long format may be more useful for some tasks, such as grouping. We take a look at total sales across the four regions to demonstrate how we can easily pass our new region column into group_by.
Data Description: 0:00
Using Pivot Longer: 0:52
Our New Dataset: 2:23
Most Sales by Region: 2:48
コメント