Tidyr
Changing data format
10. Spreading the long format out
Summary

Instruction

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).

Exercise

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

Stuck? Here's a hint!

Type:

spread(unemployment2, year, rate_u)