Tidyr
Changing data format
Summary
12. Exercise 1

Instruction

That's all for this part! Let's have a quick summary of everything we learned about tidyr.

We learned only four functions in this section, but when it's time to tidy up a dataset, these four functions are very important. They are:

  • gather() – transforms variables into new columns; creates a long-format dataset.
  • spread() – spreads values across two or more columns; creates a wide-format dataset.
  • separate() – creates one or more new columns from values in one column.
  • unite() – joins two or more columns into one column.

Let's practice what we've learned.

Exercise

We have a new dataset in memory, cars. It contains data about car sales, including the car brand, the owner's name and phone number, and an area code. Let's look at the data using glimpse().

Stuck? Here's a hint!

Type:

glimpse(cars)