Start free trial
Trending New Genres Authors
EnglishEnglish
EspañolSpanish
简体中文Chinese
繁體中文Chinese (Traditional)
FrançaisFrench
DeutschGerman
日本語Japanese
PortuguêsPortuguese
ItalianoItalian
한국어Korean
РусскийRussian
NederlandsDutch
العربيةArabic
PolskiPolish
हिन्दीHindi
Tiếng ViệtVietnamese
SvenskaSwedish
ΕλληνικάGreek
TürkçeTurkish
ไทยThai
ČeštinaCzech
RomânăRomanian
MagyarHungarian
УкраїнськаUkrainian
IndonesiaIndonesian
DanskDanish
SuomiFinnish
БългарскиBulgarian
עבריתHebrew
NorskNorwegian
HrvatskiCroatian
CatalàCatalan
SlovenčinaSlovak
LietuviųLithuanian
SlovenščinaSlovenian
СрпскиSerbian
EestiEstonian
LatviešuLatvian
فارسیPersian
മലയാളംMalayalam
தமிழ்Tamil
اردوUrdu
Searching...
SoBrief
R for Data Science

R for Data Science

Import, Tidy, Transform, Visualize, and Model Data
Turn messy tables into trustworthy analysis, from first import to a report others can rerun.
by Hadley Wickham 2016 521 pages
4.53
1k+ ratings
Listen
Immersive
V2.3
Amazon Kindle Audible
Try Full Access for 3 Days
Unlock listening & more!
Continue

Key Takeaways

Turn raw tables into insight through iteration, not a one-way checklist.

Analysis is a cycle. The book maps a data project from importing files, through tidying and transforming data, to visualization, modeling, and communication. But the work rarely follows that order once. A plot may reveal a strange pattern, prompting a new question, a revised transformation, or even a closer look at the source data. Programming supports every stage by making analysis repeatable and easier to revise.

Start with useful limits. The tools focus on rectangular, in-memory datasets, not every data problem. The authors estimate that this toolkit covers roughly 80% of a typical project, while larger datasets or unusual formats call for other methods. The point is to build a sturdy working foundation, not to mistake one book for all of data science.

Analysis

What's valuable here is the refusal to treat analysis as a conveyor belt. The iterative picture resembles scientific inquiry: observation sharpens questions, and revised questions determine what counts as relevant evidence. It also encourages a practical discipline, because each transformation should be revisable rather than hidden in an opaque sequence. The limitation is that the workflow begins once data is available. In real projects, decisions about who collected it, what was excluded, and how measurements were defined can shape conclusions as much as any R command.

A plot is assembled. The grammar of graphics is a way to construct visualizations by specifying data, mappings from variables to visual properties, and graphical layers. In ggplot2, a point layer can show observations, a smooth layer can summarize a trend, and facets can divide a display into comparable groups. Scales, statistical summaries, coordinate systems, and position adjustments further shape what appears.

Let the data surprise you. The book begins with 234 car observations: plotting engine size against highway fuel economy shows that larger engines tend to use more fuel. Coloring the points by vehicle class then reveals that some apparent high-mileage exceptions are two-seat sports cars, not the hybrids one might have guessed. The visualization changes the explanation, not just the appearance.

Analysis

This approach treats chart design as part of reasoning. Choosing color, position, or a facet determines which differences are easy to perceive, much as instrument design shapes what a scientist can observe. The compositional structure is powerful because a small number of visual decisions can generate many useful views without memorizing recipes. Still, more encodings do not automatically mean more information: color can become illegible, and a smooth line can imply a pattern that the data do not support. Clear plots make their analytical choices visible.

Put each variable in a column, then transform with readable verbs.

Tidy data has a shape. Tidy data stores each variable in its own column, each observation in its own row, and each value in its own cell. That consistency lets R's vector-based functions work naturally and reduces the effort spent reshaping data for different tools. The book demonstrates tidying tuberculosis statistics by gathering dozens of coded columns, then separating their labels into fields such as age group and diagnosis type.

Use small operations. The dplyr verbs filter rows, arrange them, select columns, create variables with mutate(), and summarize values. Grouping lets the same operations work by destination, date, or another category. Chaining these steps with `%>%` reads like a sequence of actions, making an analysis easier to inspect than a pile of unnamed intermediate objects.

Analysis

A consistent schema is a form of cognitive infrastructure: it lets analysts focus on the meaning of a calculation instead of repeatedly decoding a table's layout. This connects to database normalization, where explicit fields make relationships and operations easier to manage. The tidy arrangement is not universally optimal, however. Matrices, images, and other specialized data may have more natural structures, and a wide table can suit some reporting tasks. Tidy data is most useful as a practical default for rectangular analysis, not as a law that every dataset must obey.

Treat parsing warnings and missing values as evidence, not housekeeping.

Imports need checking. readr guesses column types by inspecting an initial sample, so a file can contain values that contradict the guess. In the book's example, a column first appears to contain integers, then includes decimals; another column ends with dates. Inspect parsing problems, and specify column types when reliable imports matter. Dates and times also require care: daylight saving changes mean that a calendar day is not always a fixed number of seconds.

Absence has meaning. A missing value may signal a cancelled flight, an unrecorded measurement, or an observation that never existed in the table. In the diamond data, nine records have impossible zero measurements; the authors replace those measurements with missing values rather than deleting every associated fact. Investigate unusual values, preserve useful information, and explain any exclusions.

Analysis

Data cleaning is a measurement problem, not cosmetic tidying. Missingness can reflect the process that generated the data, so deleting incomplete rows may systematically remove particular people, events, or conditions. Statistical practice distinguishes mechanisms such as random loss from values missing for a reason, and that distinction can change what conclusions are defensible. Parsing warnings are similarly useful because they expose a mismatch between the file and the analyst's expectations. The book's recommendation to inspect and justify corrections is stronger than the tempting shortcut of making every import look clean.

Verify table keys before joining, or your rows can multiply silently.

Keys establish relationships. A primary key uniquely identifies a row in its own table; a foreign key points to a related row elsewhere. In the flight data, a plane's tail number identifies it in the planes table and links flights to that plane. Weather records require a combination of location and time fields to distinguish observations.

Check cardinality first. A left join keeps every row from the main table while adding matching information. It is often the safest lookup, but duplicated keys on both sides can create every possible pair of matches and inflate the result. The book recommends checking whether proposed keys are unique and using anti-joins to find unmatched records. A successful command is not proof that the tables joined as intended.

Analysis

This is the data-analysis version of referential integrity: relationships should be validated, not inferred from a join that happens to run. The lesson also applies beyond R, since SQL databases and distributed data systems face the same risks when keys are ambiguous. A useful audit includes expected row counts, uniqueness checks, and inspection of unmatched keys. Row counts alone can mislead, though: rows lost through unmatched records can be offset by rows added through duplicated keys, leaving a plausible total that conceals a broken relationship.

Store repeated analyses together in functions, maps, and list-columns.

Abstract repetition. When the same block of code appears three times, the book recommends turning it into a function with a clear name and inputs. For loops handle repeated work explicitly; purrr's map functions apply a function across inputs while making the output type clear. Preallocating results or collecting them in a list avoids repeatedly growing an output object.

Keep related work aligned. A list-column is a table column whose cells can hold objects such as datasets or fitted models. A nested data frame uses one row per group and stores that group's observations in a list-column. The book fits a simple trend for each of 142 countries in the Gapminder data, keeps each model beside its country, and uses broom to turn model summaries into ordinary columns for comparison.

Analysis

These tools reduce bookkeeping errors by keeping related results attached to the entities they describe. That is a broader design principle: data structures can enforce alignment that would otherwise depend on memory and discipline. Functional abstractions also make intent easier to review, especially when the same operation is applied across many groups. Their cost is indirection. A map pipeline or list-column can feel opaque to a beginner, so clarity depends on named functions, predictable output types, and small steps that can be inspected when an analysis fails.

Use models to expose patterns, then inspect what their residuals leave behind.

A model is an approximation. The book treats a fitted model as the closest member of a chosen family under a defined measure of distance, not as a discovery of literal truth. A residual is the difference between an observed value and the model's prediction. Looking at residuals helps show what the model has not explained.

Peel away strong effects. Diamond prices rise sharply with carat size, obscuring how cut, color, and clarity relate to price. The authors model log price from log carat, then examine the remaining differences; higher-quality diamonds are more expensive relative to their size. This is exploratory evidence, not automatic confirmation. Reusing observations to invent and test a hypothesis can overstate confidence, so formal confirmation requires data reserved for that purpose.

Analysis

Residual analysis is a useful bridge between prediction and interpretation: it reveals whether a simple account has left a structured pattern behind. The diamond example also illustrates confounding, where a dominant variable such as size distorts comparisons between quality groups. But a clean-looking residual plot does not prove that a model is correct; omitted variables, measurement error, and model assumptions can remain invisible. The book's distinction between exploration and confirmation is essential. Its suggested training, query, and test split is a helpful template, though time-dependent data often requires holdouts that preserve chronological order.

Make every result rerunnable, and every plot legible to outsiders.

Save the recipe. An RStudio project keeps a project's data, scripts, and outputs together, while relative paths make it easier to move the project between computers. The authors advise treating scripts, not a remembered interactive workspace, as the durable record of an analysis. A clean session that reruns the script is a practical test of whether the work has been captured.

Write for an audience. R Markdown combines prose, code, and computed results in one document, which can become a report, notebook, presentation, or dashboard. For a public-facing plot, replace cryptic variable names with clear titles, units, captions, and labels. Caching can save time on expensive calculations, but dependencies must be tracked or stale results may survive a code change.

Analysis

Reproducibility is both a technical and communicative achievement. A script that reruns helps future analysts verify the computation, while an explanation helps them understand why the computation answers the question. This resembles literate programming, where code and reasoning are maintained as one artifact. Re-execution alone is not enough: software versions, input data provenance, and the choices made during cleaning also matter. The book's project and notebook habits establish a strong foundation, especially when paired with version control and explicit records of analytical decisions.

Analysis

The book's central achievement is to teach a way of thinking through a toolkit. Its sequence begins with visible rewards, especially plots, then introduces transformation, data structure, programming, modeling, and communication. That order matters pedagogically: learners see why data work is worth doing before confronting the often tedious realities of importing and cleaning it. The recurring examples, from car fuel economy to flights, diamonds, and country-level life expectancy, make the tools feel like parts of one analytical practice rather than isolated package tutorials.

Its strongest conceptual move is to connect representation with reasoning. Tidy tables make operations more consistent; visual encodings expose patterns; grouping and joins make the unit of analysis explicit; residuals isolate what a model leaves unexplained. These are not merely conveniences. Each choice influences what questions become easy to ask and what errors become easy to notice. The book is especially good at showing that code organization, data organization, and analytical judgment are related problems. The approach also has boundaries. A clean pipeline can still answer a poorly framed question, and a persuasive visualization can make a correlation seem more meaningful than it is. Models are presented chiefly as exploratory instruments, which is useful for learning but does not replace design, causal reasoning, or rigorous validation. The examples also emphasize rectangular, in-memory data and a particular R ecosystem. Since this edition dates to 2016, some package interfaces and recommendations may have changed; current documentation matters for implementation. The underlying principles remain more durable than any specific function call: make assumptions inspectable, preserve the path from raw inputs to conclusions, and treat analysis as a revisable argument rather than a sequence of commands.

Summary in 30 Seconds
Data analysis is iterative: plots can raise new questions, and each transformation should remain inspectable. Organize tables with one variable per column and one observation per row, then check parsing issues, missing values, and join keys before trusting results. Use visual encodings to reveal patterns, and examine model residuals to see what remains unexplained. Keep scripts, data, and outputs together so analyses can be rerun and communicated clearly.
Contains spoilers

Last updated:

Report Issue
Want to read the full book?

Glossary

Tidy data

Consistent table structure

A way of organizing rectangular data so each variable occupies a column, each observation occupies a row, and each value occupies its own cell. This structure lets common analysis tools operate consistently across datasets and reduces repeated reshaping. It is a useful default for tabular analysis, not a requirement for every kind of data.

Grammar of graphics

Composable plot construction

A system for describing a visualization through its data, mappings between variables and visual properties, geometric layers, statistical transformations, position adjustments, coordinate system, and facets. In ggplot2, these components can be combined to create many plots from a shared structure instead of relying only on separate chart recipes.

Exploratory data analysis

Iterative pattern discovery

An open-ended process of generating questions about data, investigating them with visualization, transformation, and modeling, then refining the questions in response to what appears. It also helps identify data-quality problems. The process is for developing understanding and candidate explanations; findings from repeated exploration should not be presented as independent confirmation.

List-column

Objects stored in cells

A data-frame column whose entries are lists, allowing each row to hold an object such as a vector, dataset, or fitted model. List-columns are useful for keeping group-specific inputs and results aligned in one table. They often serve as an intermediate structure, later simplified into ordinary columns or expanded into rows.

Residual

Observed minus predicted

The difference between an observed response and the value predicted by a fitted model for that observation. Examining residuals can reveal patterns the model has not captured and show how far predictions deviate from the data. Residuals are informative diagnostics, but their appearance alone cannot establish that a model or its assumptions are correct.

Nested data frame

One row per group

A data frame in which each row represents a group or meta-observation, while a list-column contains the ordinary observations belonging to that group. For example, country-level rows can each contain a smaller table of annual measurements. This format supports applying the same analysis separately to many groups while keeping their results together.

R Markdown

Code and prose documents

A document format that combines narrative text, R code, and computed output. Rendering executes code and produces outputs such as HTML, PDF, Word documents, presentations, dashboards, or websites. It can support analysis notebooks and reports, helping preserve both the results and the steps used to produce them.

Download PDF

To save this R for Data Science summary for later, download the free PDF. You can print it out, or read offline at your convenience.
Download PDF
File size: 0.23 MB     Pages: 13

Download EPUB

To read this R for Data Science summary on your e-reader device or app, download the free EPUB. The .epub digital book format is ideal for reading ebooks on phones, tablets, and e-readers.
Download EPUB
File size: 1.26 MB     Pages: 15
Want to read the full book?
Follow
Listen
Home
Swipe
Library
Get App
Try Full Access for 3 Days
Listen, bookmark, and more
Compare Features Free Pro
📖 Read Summaries
Read unlimited summaries. Free users get 3 per month
🎧 Listen to Summaries
Listen to unlimited summaries in 40 languages
—
❤️ Unlimited Bookmarks
Free users are limited to 4
—
📜 Unlimited History
Free users are limited to 4
—
📥 Unlimited Downloads
Free users are limited to 1
—
Risk-Free Timeline
Today: Get Instant Access
Listen to full summaries of 26,000+ books. That's 12,000+ hours of audio!
Day 2: Trial Reminder
We'll send you a notification that your trial is ending soon.
Day 3: Your subscription begins
You'll be charged on Nov 24,
cancel anytime before.
Consume 2.8× More Books
2.8× more books Listening Reading
Our users love us
1M+ readers
Trustpilot Rating
TrustPilot
4.6 Excellent
This site is a total game-changer. I've been flying through book summaries like never before. Highly, highly recommend.
— Dave G
Worth my money and time, and really well made. I've never seen this quality of summaries on other websites. Very helpful!
— Em
Highly recommended!! Fantastic service. Perfect for those that want a little more than a teaser but not all the intricate details of a full audio book.
— Greg M
Save 62%
Yearly
$119.88 $44.99/year/yr
$3.75/mo
Monthly
$9.99/mo
Start a 3-Day Free Trial
3 days free, then $44.99/year. Cancel anytime.
Unlock a world of fiction & nonfiction books
26,000+ books for the price of 2 books
Read any book in 10 minutes
Discover new books like Tinder
Request any book if it's not summarized
Read more books than anyone you know
#1 app for book lovers
Lifelike & immersive summaries
30-day money-back guarantee
Download summaries in EPUBs or PDFs
Cancel anytime in a few clicks

Why one summary?

Scanner
Find a barcode to scan

⭐
⭐
⭐
We have a special gift for you
Open
38% off
DISCOUNT FOR YOU
⭐
⭐
⭐
$79.99
$49.99/year
Only $4.16 per month
Continue
2 taps to start, super easy to cancel
Settings
General
Widget
Loading...