You are here

A Survivor's Guide to R
Share
Share

A Survivor's Guide to R
An Introduction for the Uninitiated and the Unnerved



June 2014 | 488 pages | SAGE Publications, Inc
Focusing on developing practical R skills rather than teaching pure statistics, Dr. Kurt Taylor Gaubatz’s A Survivor’s Guide to R provides a gentle yet thorough introduction to R. The book is structured around critical R tasks, and focuses on applied knowledge, rather than abstract concepts. Gaubatz’s easy-to-read approach helps students with little or no background in statistics or programming to develop real-world R skills through straightforward coverage of R objects and functions. Focusing on real-world data, the challenges of dataset construction, and the use of R’s powerful graphing tools, the guide is written in an accessible, sympathetic, even humorous style that ensures students acquire functional R skills they can use in their own projects and carry into their work beyond the classroom.
 
Chapter 1: Getting Started
Things Your Statistics Class Probably Won't Teach You

 
Why R?

 
Statistical Modeling

 
A Few R Basics

 
Saving Your Work

 
R Packages

 
Help with R Help

 
Organization of this Book

 
 
Chapter 2: A Sample Session
Reviewing Your Data

 
Data Visualization

 
Hypothesis Testing for Fun and Profit

 
A Regression Model

 
A Nonlinear Model

 
 
Chapter 3: Object Types in R
R Objects And Their Names

 
How to Think about Data Objects in R

 
R Object Storage Modes

 
R Data Object Types

 
The Basic Data Objects: Vectors

 
The Basic Data Objects: Matrices and Their Indices

 
The Basic Data Objects: Data Frames

 
The Basic Data Objects: Lists

 
A Few Things about Working with Objects

 
Object Attributes

 
Objects and Environments

 
R Object Classes

 
The Pseudo Storage Modes

 
Date and Time as a Storage Modes

 
Factors

 
Coercing Storage Modes

 
The Curse of Number-Character-Factor Confusion

 
Conclusions

 
 
Chapter 4: Getting Your Data Into R
Entering Data

 
Creating Data

 
Importing Data

 
The Read Command: Overview

 
The Read Command: Reading from the Clipboard

 
The Read Command: Blank Delimited Tables

 
The Read Command: Comma Separated Values

 
The Read Command: Tab Separated Data

 
The Read Command: Fixed-Width Data

 
Importing Foreign File Types

 
Integrating SQL with R

 
Extracting Data from Complex Data Sources

 
Web Scraping

 
Dealing with Multi-Dimensional Data

 
Importing Problematic Characters

 
More Resources

 
 
Chapter 5: Reviewing and Summarizing Data
Summary Functions

 
Checking A Sample Of Your Data

 
Reviewing Data By Categories

 
Displaying Data With A Histogram

 
Displaying Data With A Scatter Plot

 
Scatter Plot Matrices

 
 
Chapter 6: Sorting and Selecting Data
Using Index Values to Select Data

 
Using Conditional Values for Selecting

 
Using Subset( ) with Variable or Row Names to Select Data

 
Splitting a Dataset into Groups

 
Splitting Up Continuous Numeric Data

 
Sorting And Ordering Data

 
 
Chapter 7: Transforming Data
Creating New Variables

 
Editing Data

 
Basic Math with R

 
R Functions

 
Math and Logical Functions in R

 
Truncation and Rounding Functions

 
The Apply( ) Family of Functions

 
Changing Variable Values Conditionally

 
Creating New Functions

 
Additional R Programming

 
Character Strings as Program Elements and Program Elements as Character Strings

 
 
Chapter 8: Text Operations
Some Useful Text Functions

 
Finding Things

 
Regular Expressions

 
Processing Raw Text Data

 
Scraping the Web for Fun And Profit

 
 
Chapter 9: Working With Date And Time DataDates in R
Dates in R

 
Formatting Dates for R

 
Working with POSIX Dates

 
Special Date Operations

 
Formatting Dates for Output

 
Time Series Data

 
Creating Moving Averages in Time-Series Data

 
Lagged Variables in Time-Series Data

 
Differencing Variables in Time-Series Data

 
The Limitations of ts Data

 
 
Chapter 10: Data Merging And Aggregation
Dataset Concatenation

 
Match Merging

 
Keyed Table Look-up Merging

 
Aggregating Data

 
Transposing and Rotating Datasets

 
 
Chapter 11: Dealing with Missing Data
Reading Data with Missing Values

 
Summarizing Missing Values

 
The Missing Values Functions

 
Recoding Missing Values

 
Missing Values And Regression Modeling

 
Visualizing Missing Data

 
 
Chapter 12: R Graphics I: The Built-in Plots
Scatter Plots

 
Pairs Plots

 
Line Plots

 
Box Plots

 
Histograms, Density Plots, and Bar Charts

 
Dot Charts

 
Pie Charts

 
Mosaic Plots

 
Conclusions

 
 
Chapter 13: R Graphics II: The Boring Stuff
The Graphics Device

 
Graphics Parameters

 
The Plot Layout

 
Graphic Coordinates in R

 
Overlaying Plots

 
Multiple Plots

 
Conclusions

 
 
Chapter 14: R Graphics III: The Fun Stuff--Text
Adding Text

 
Setting up a Font

 
Titles and Subtitles

 
Creating a Legend

 
Simple Axes and Axis Labels

 
Building More Complex Axes

 
Ad-hoc Text

 
 
Chapter 15: R Graphics IV: The Fun Stuff--Shapes
Doing Colors

 
Custom Points

 
Adding Lines

 
Shapes

 
Incorporating Images into Plots

 
A Final Word about Aesthetics

 
 
Chapter 16 from Here to Where?

Supplements

Companion Website
R code, graphics, and data are available on the book's companion site.

“The guide is detailed enough that students could practice these operations outside the classroom until they mastered them, which means that more class time can be spent discussing the conceptual issues in statistics.”

Ole J. Forsberg, Oklahoma State University

“R's visualization tools and its powerful graphics capabilities . . . make this book a popular choice for many applications.”

Charlotte Tate, San Francisco State University

“A strength is the author's thorough approach to the code without being . . . dull.  I very much appreciate that the author describes R code idiosyncrasies while keeping the text light.”

Yulan Liang, University of Maryland, Baltimore

“[This book] does an excellent job of guiding readers through pitfalls common to R's data handling idiosyncrasies—pitfalls usually learned after hours of frustration and lamentation. The conversational, and at times humorous, style makes for a readable, enjoyable, and relaxed examination of a powerful computation tool with a steep learning curve. Each chapter is compartmentalized enough to be read separately, but the author includes chapter references . . . to tie the guide together as a whole . . . The author covers the full spectrum, plus, thankfully, quite a bit of  material not usually included in other R introductions . . . The author covers the material in depth with nicely done examples.  I was also very happy to see that the author included a section on programming etiquette in R—very nice.”

A. Dean Monroe, Angelo State University

“I very much appreciate the development of a text primarily devoted to the students and practitioners who are first-time users of R . . . It is a very gentle and easy-to-read introduction to R for anyone who might have been afraid of learning programming language . . . It [is] very easy to read and follow . . . The flow of the topics is logical and natural for teaching any computational language. With a good sense of humor, the text is highly user-friendly.”

Professor David Han, University of Texas, San Antonio

My university and department has yet to allow me to teach R instead of SPSS. However, this is a terrific text, and I hope to see an updated version soon when it becomes clear that we should be teaching and using R instead of, or in conjunction with, SPSS.

Dr Angela Birt
Psychology, Mount St Vincent University
August 21, 2015

Very useful for supporting learning of R. Good introduction and useful for reference.

Dr Mark Ramsden
Department of Sociology, Cambridge University
June 25, 2015

This is a helpful book for students doing data analysis with R.

Dr Katharina Manderscheid
Soziologisches Seminar, University of Lucerne
February 3, 2015

A "Survivor's guide to R" is a nice introduction for the more technical details of R which are essential to make fully use of R's statistical capacities. It is useful for beginners of R who have little or no experience with programming languages. It is easy and nice to read (at least as such a technical topic can be).

Dr Daniel Stahl
Biostatistics and Computing, King's College London
December 17, 2014

good book but not for undergraduates

Dr Tuo Yu Chen
Health and Human Sciences Program, Albany College of Pharmacy and Health Sciences
October 22, 2014

Sample Materials & Chapters

Chapter 3

Chapter 14


For instructors

Select a Purchasing Option

SAGE Research Methods is a research methods tool created to help researchers, faculty and students with their research projects. SAGE Research Methods links over 175,000 pages of SAGE’s renowned book, journal and reference content with truly advanced search and discovery tools. Researchers can explore methods concepts to help them design research projects, understand particular methods or identify a new method, conduct their research, and write up their findings. Since SAGE Research Methods focuses on methodology rather than disciplines, it can be used across the social sciences, health sciences, and more.

With SAGE Research Methods, researchers can explore their chosen method across the depth and breadth of content, expanding or refining their search as needed; read online, print, or email full-text content; utilize suggested related methods and links to related authors from SAGE Research Methods' robust library and unique features; and even share their own collections of content through Methods Lists. SAGE Research Methods contains content from over 720 books, dictionaries, encyclopedias, and handbooks, the entire “Little Green Book,” and "Little Blue Book” series, two Major Works collating a selection of journal articles, and specially commissioned videos.