R tutorial: How to reshape data in R

This book excerpt from “R for Everyone” details the methods in the R programming language to prepare your data for analysis

R tutorial: How to reshape data in the R programming language

Combining multiple datasets, whether by stacking or joining, is commonly necessary as is changing the shape of data. The plyr and reshape2 packages offer good functions for accomplishing this in addition to base tools such as rbind, cbind, and merge.

Manipulating data takes a great deal of effort before serious analysis can begin. In this chapter, I 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 I 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 supersede them.

cbind and rbind

To continue reading this article register now

How to choose a low-code development platform