From the course: Learning the R Tidyverse

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Convert data from wide to long

Convert data from wide to long - R Tutorial

From the course: Learning the R Tidyverse

Start my 1-month free trial

Convert data from wide to long

- [Instructor] Tidyr is a member of the tidyverse and provides a number of verbs for reshaping and transforming data. The gather verb is used to convert wide data into long or tidy data. The template for gather is fairly simple. You pipe your data in and you specify the name of two new columns in the first two arguments of gather. The first argument is key, which takes the column names that you specify together after the second argument. And value is the name of the column which will contain all of the values from the columns that you specify in the third argument onwards. So everything after the key and the value column is the name of a column that you wish to pull out of your DataFrame and to insert into this new key and value column. There are a number of different ways but you can specify the column names in the third argument onwards, and it's important to note that in R, if you want to refer to every argument after this argument, you use the three dots. So when we read this…

Contents