Chapter 12. 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 needs 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
.
12.1. cbind and rbind
The simplest case is when we have two datasets with either identical columns (both the number of and names) or the same number of rows. In this case, either rbind
or cbind
work great.
As a first trivial example, we create two simple data.frame
s by combining a few vector ...
Get R for Everyone: Advanced Analytics and Graphics 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.