Tidying and Reshaping Data
Echoing Leo Tolstoy’s wisdom (“Happy families are all alike; every unhappy family is unhappy in its own way.”), Hadley Wickham tells us, all tidy data is fundamentally alike, but all untidy data is messy in its own special way. How many times have we all stared at some rows of data and thought, “What… how... why did they do that?” This overstates the case somewhat. Although there are many ways that data can be poorly structured, there are limits to human creativity in this regard. It is possible to categorize the most frequent ways in which datasets deviate from normalized or tidy forms.
This was Hadley Wickham’s observation in his seminal work on tidy data. We can lean on that work, and our own experiences with oddly structured data, to prepare for the reshaping we have to do. Untidy data often has one or more of the following characteristics: a lack of clarity about merge-by column relationships; data...