14. Data Reshaping
As noted in Chapter 11, manipulating the data takes a great deal of effort before serious analysis can begin. In this chapter we will consider when the data need to be rearranged from column-oriented to row-oriented (or the opposite) and when the data are in multiple, separate sets and need to be combined into one.
There are base functions to accomplish these tasks, but we will focus on those in plyr, reshape2 and data.table.
While the tools covered in this chapter still form the backbone of data reshaping, newer packages like tidyr and dplyr are starting to supercede them. Chapter 15 is an analog to this chapter using these new packages.
14.1 cbind
and rbind
The simplest case is when we have a two datasets with either identical ...
Get R for Everyone: Advanced Analytics and Graphics, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.