What’s Pivoting
Pivoting is taking a dataset and reshaping it to change how columns and rows are organized. It’s easiest to understand with a visual example. Here are two tables that are pivots of one another.

We refer to the first table as being in “wide” format and the second in “long” format.
The wide format table is more commonly used when you are creating your own datasheet because it’s easier to enter data in wide format. You can see that there is a lot less repition in the wide data. But the long format is often much easier to analyze. In long format, every row contains all the information for a single measurement and each column represents the same type of data. Long format data is also frequently referred to as “tidy data”.
When we pivot tables we are moving between long and wide format. To move between the two types we’ll use two functions: pivot_longer() and pivot_wider().