From the course: Cleaning Bad Data in R

Unlock the full course today

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

Making wide data sets long

Making wide data sets long

From the course: Cleaning Bad Data in R

Start my 1-month free trial

Making wide data sets long

- [Narrator] Analysts working in R often find themselves in the situation where they would like to convert a wide data set into a longer version. The gather function makes this easy. In the last video, we looked at this example of a Pew Religion data set that is wide, and described how a data scientist might prefer to convert it into a longer format. Let's now take a look at how to perform this conversion in R. The tidyr library within the tidyverse contains a function called gather that takes a wide data set and makes it long by gathering the information from columns and putting it into rows. The gather function works using the concept of keys and values. Value means the same thing that it does in the world of tidy data. It's the actual data point in a table that represents the observation of a single variable. Keys are a new term to us. The key is the name used to identify the variable described by the value. In the case of making a wide data set long, the key is usually the column…

Contents