Free Trial
Join Class
Search:

R for Data Science: Import, Tidy, Transform, Visualize, and Model Data

Hadley Wickham and Garrett Grolemund's text paired with RStudio for a seamless learning experience

ADD TO MY ACCOUNT

Table of Contents

  1. Introduction
  2. Explore
    1. Introduction
    2. Data Visualization
    3. Workflow: basics
    4. Data transformation
    5. Workflow: scripts
    6. Exploratory Data Analysis
    7. Workflow: projects
  3. Wrangle
    1. Introduction
    2. Tibbles
    3. Data import
    4. Tidy data
    5. Relational data
    6. Strings
    7. Factors
    8. Data and times
  4. Program
    1. Introduction
    2. Pipes
    3. Functions
    4. Vectors
    5. Iteration
  5. Model
    1. Introduction
    2. Model basics
    3. Model building
    4. Many models
  6. Communicate
    1. Introduction
    2. R Markdown
    3. Graphics for communication
    4. R Markdown formats
    5. R Markdown workflow

Book Description

"This book will teach you how to do data science with R: You’ll learn how to get your data into R, get it into the most useful structure, transform it, visualise it and model it. In this book, you will find a practicum of skills for data science. Just as a chemist learns how to clean test tubes and stock a lab, you’ll learn how to clean data and draw plots—and many other things besides. These are the skills that allow data science to happen, and here you will find the best practices for doing each of these things with R. You’ll learn how to use the grammar of graphics, literate programming, and reproducible research to save time. You’ll also learn how to manage cognitive resources to facilitate discoveries when wrangling, [visualizing], and exploring data."

r4ds.had.co.nz

Introduction

Data science is a huge field, and there’s no way you can master it by reading a single book. The goal of this book is to give you a solid foundation in the most important tools. Our model of the tools needed in a typical data science project looks something like this:

First you must import your data into R. This typically means that you take data stored in a file, database, or web API, and load it into a data frame in R. If you can’t get your data into R, you can’t do data science on it!

Once you’ve imported your data, it is a good idea to tidy it. Tidying your data means storing it in a consistent form that matches the semantics of the dataset with the way it is stored. In brief, when your data is tidy, each column is a variable, and each row is an observation. Tidy data is important because the consistent structure lets you focus your struggle on questions about the data, not fighting to get the data into the right form for different functions.

Once you have tidy data, a common first step is to transform it. Transformation includes narrowing in on observations of interest (like all people in one city, or all data from the last year), creating new variables that are functions of existing variables (like computing speed from distance and time), and calculating a set of summary statistics (like counts or means). Together, tidying and transforming are called wrangling, because getting your data in a form that’s natural to work with often feels like a fight!

Once you have tidy data with the variables you need, there are two main engines of knowledge generation: visualisation and modelling. These have complementary strengths and weaknesses so any real analysis will iterate between them many times.

Visualisation is a fundamentally human activity. A good visualisation will show you things that you did not expect, or raise new questions about the data. A good visualisation might also hint that you’re asking the wrong question, or you need to collect different data. Visualisations can surprise you, but don’t scale particularly well because they require a human to interpret them.

Models are complementary tools to visualisation. Once you have made your questions sufficiently precise, you can use a model to answer them. Models are a fundamentally mathematical or computational tool, so they generally scale well. Even when they don’t, it’s usually cheaper to buy more computers than it is to buy more brains! But every model makes assumptions, and by its very nature a model cannot question its own assumptions. That means a model cannot fundamentally surprise you.

The last step of data science is communication, an absolutely critical part of any data analysis project. It doesn’t matter how well your models and visualisation have led you to understand the data unless you can also communicate your results to others.

Surrounding all these tools is programming. Programming is a cross-cutting tool that you use in every part of the project. You don’t need to be an expert programmer to be a data scientist, but learning more about programming pays off because becoming a better programmer allows you to automate common tasks, and solve new problems with greater ease.

— R for Data Science

Take a peek inside...

  • Written by Hadley Wickham, a key developer in R packages
  • RStudio IDE next to text to follow along
  • Run code with the push of a button

R4DS

 

Ready to Get Started?

Add this content to your Codio account!

ADD TO MY ACCOUNT