Reshaping Your Data (Long to Wide, Wide to Long)

I am currently teaching an Introductory R class for Health, Behavioral, Educational, and Social Scientists. As such, I created a PDF handout describing the base R function reshape() to help the students to better comprehend each of the arguments and how it moves the data. It is a flexible function that can change your data from wide to long format and vice versa. Other functions, including those in the tidyverse, are very helpful too (e.g., gather() and spread()) although I do not cover these in any depth in the handout.

One of the great benefits of reshape() is that it can easily reshape the data based on several variables/measures [e.g., depression measured at time 1 (depr1) and time 2(depr2) and anxiety measured at time 1 (anx1) and time 2 (anx2)]. This is shown in the handout, from wide to long and long to wide.

A PNG copy of the handout is shown below.

Reshaping