From the course: Learning the R Tidyverse
Unlock the full course today
Join today to access over 24,100 courses taught by industry experts.
Using pivot_longer() to tidy data into a long format - R Tutorial
From the course: Learning the R Tidyverse
Using pivot_longer() to tidy data into a long format
- For Tidyverse contains a pair functions that work in tandem for pivoting data between wide and long format, pivot_longer and pivot_wider. It's important to note that before 2020, these processes were achieved with a pair of functions called gather() and spread(). It's becoming less and less common to see those functions gather() and spread() in the wild, and that's because the new pivot functions are more powerful and come with lots of features that just weren't available in these old deprecated functions. So I'm going to demonstrate how to use pivot_longer as it's the most complex and the most useful function of the two. And then at the end of this video, I'll quickly demonstrate, pivot_wider to undo all of our work, making our data longer. So let's go over to project O2_O3B to see this in action. Okay, the top of the script, let's load the Tidyverse and let's read in my dataset UN data. Let's take UN data, let's print it to the console. And we can see that we've got four columns…
Contents
-
-
-
-
What is tidy data?3m 2s
-
(Locked)
Why does ggplot2 want tidy data?4m 22s
-
(Locked)
Using pivot_longer() to tidy data into a long format4m 26s
-
(Locked)
Cleaning column names with the janitor package3m 21s
-
(Locked)
Tidying columns containing multiple values with separate_*()4m 44s
-
(Locked)
List columns and nested tibbles5m 3s
-
-
-
-
-
-