Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Changing data format
10. Spreading the long format out


However, sometimes we do need our data in wide format. How would we make that happen?

We don't have to re-load the file; the spread() function will turn long data into wide format. It takes key-value pairs and spreads them across several columns. If we wanted our population to go back to its original format, we'd write:

spread(population, year, amount)

The arguments are the name of the dataset (population), the name of the column containing the values that will become the new column names (year), and the name of the column with the row values (amount).


Using spread(), turn the data in the unemployment2 columns year and rate_u into wide format.

Stuck? Here's a hint!


spread(unemployment2, year, rate_u)