Chapter 3

Wrangling data

We’ve gone through different methods of bringing in various types of data sets into R.

Now we’re going to learn the proper methods of transforming and analyzing the data.

We’ll be using the dplyr and tidyr packages.

With verb-like names for functions, dplyr and tidyr turn data analysis into a sort-of grammar exercise and avoids the mess of nested functions that can tangle users in Base R.

This lends itself to better documentation because others will be able to read your code later on and follow what you were trying to accomplish.


Files and folders

The repo for this class is on Github, but can be easily downloaded to your desktop with the following commands:



Test yourself

There are links to exercise what you’ve learned spread through out this section.

It’s possible to run these files locally to test yourself if you’ve downloaded the files for the chapter as instructed above.

Make sure your project directory is correct and then run these lines in the console:


and then



© Copyright 2018, Andrew Ba Tran

© Copyright 2018, Andrew Tran