Tidyr package is used to create tidy data. Tidy data is a standard way of storing data that is used to ensure that we spend less time fighting with the tools and more time working on the analysis. The different functions of Tidyr package are described here.
Problem:
Use of Tidyr Spread() in R
Solution:
In some scenarios, we are required to turn long formatted data into wide formatted data. The spread() function generates multiple columns from two columns:
1. each unique value in the key column becomes a column name
2. each value in the value column becomes a cell in the new columns
Let’s work on the iris1 dataset that we created in the Tidyr:: Gather() post.
iris1 |
Spread() is the complement of Gather() in Tidyr and below is the code: