Hands-on Programming with R

Hands-on Programming with R

by Garrett Grolemund
Hands-on Programming with R

Hands-on Programming with R

by Garrett Grolemund

Paperback

$39.99 
  • SHIP THIS ITEM
    Qualifies for Free Shipping
  • PICK UP IN STORE
    Check Availability at Nearby Stores

Related collections and offers


Overview

Learn how to program by diving into the R language, and then use your newfound skills to solve practical data science problems. With this book, you’ll learn how to load data, assemble and disassemble data objects, navigate R’s environment system, write your own functions, and use all of R’s programming tools.

RStudio Master Instructor Garrett Grolemund not only teaches you how to program, but also shows you how to get more from R than just visualizing and modeling data. You’ll gain valuable programming skills and support your work as a data scientist at the same time.

  • Work hands-on with three practical data analysis projects based on casino games
  • Store, retrieve, and change data values in your computer’s memory
  • Write programs and simulations that outperform those written by typical R users
  • Use R programming tools such as if else statements, for loops, and S3 classes
  • Learn how to write lightning-fast vectorized R code
  • Take advantage of R’s package system and debugging tools
  • Practice and apply R programming concepts as you learn them

Product Details

ISBN-13: 9781449359010
Publisher: O'Reilly Media, Incorporated
Publication date: 08/04/2014
Pages: 247
Sales rank: 606,107
Product dimensions: 6.90(w) x 9.10(h) x 0.60(d)

About the Author

Garrett Grolemund is a statistician, teacher and R developer who currently works for RStudio. He sees data analysis as a largely untapped fountain of value for both industry and science. Garrett received his Ph.D at Rice Universityin Hadley Wickham's lab, where his research traced the origins of data analysis as a cognitive process and identified how attentional and epistemological concerns guide every data analysis.



Garrett is passionate about helping people avoid the frustration and unnecessary learning he went through while mastering data analysis. Even before he finished his dissertation, he started teaching corporate training in R and data analysis for Revolutions Analytics. He's taught at Google, eBay, Axciom and many other companies, and is currently developing a training curriculum for RStudio that will make useful know-how even more accessible.



Outside of teaching, Garrett spends time doing clinical trials research, legal research, and financial analysis. He also develops R software, he's co-authored the lubridate R package—which provides methods to parse, manipulate, and do arithmetic with date-times—and wrote the ggsubplot package, which extends the ggplot2 package.

Table of Contents

Foreword vii

Preface ix

Part I Project 1: Weighted Dice

1 The Very Basics 3

The R User Interface 3

Objects 7

Functions 12

Sample with Replacement 14

Writing Your Own Functions 16

The Function Constructor 17

Arguments 18

Scripts 20

Summary 22

2 Packages and Help Pages 23

Packages 23

install, packages 24

library 24

Getting Help with Help Pages 29

Parts of a Help Page 30

Getting More Help 33

Summary 33

Project 1 Wrap-up 34

Part II Project 2: Playing Cards

3 R Objects 37

Atomic Vectors 38

Doubles 39

Integers 40

Characters 41

Logicals 42

Complex and Raw 42

Attributes 43

Names 44

Dim 45

Matrices 46

Arrays 46

Class 47

Dates and Times 48

Factors 49

Coercion 51

Lists 53

Data Frames 55

Loading Data 57

Saving Data 61

Summary 61

4 R Notation 65

Selecting Values 65

Positive Integers 66

Negative Integers 68

Zero 69

Blank Spaces 69

Logical Values 69

Names 70

Deal a Card 70

Shuffle the Deck 71

Dollar Signs and Double Brackets 73

Summary 76

5 Modifying Values 77

Changing Values in Place 77

Logical Subsetting 80

Logical Tests 80

Boolean Operators 85

Missing Information 89

na-rm 90

is.na 90

Summary 91

6 Environments 93

Environments 93

Working with Environments 95

The Active Environment 97

Scoping Rules 98

Assignment 99

Evaluation 99

Closures 107

Summary 112

Project 2 Wrap-up 112

Part III Project 3: Slot Machine

7 Programs 115

Strategy 118

Sequential Steps 118

Parallel Cases 119

If Statements 120

else Statements 123

Lookup Tables 130

Code Comments 136

Summary 137

8 S3 139

The S3 System 139

Attributes 140

Generic Functions 145

Methods 146

Method Dispatch 148

Classes 151

S3 and Debugging 152

S4 and R5 152

Summary 152

9 Loops 155

Expected Values 155

expand.grid 157

for Loops 163

while Loops 168

repeat Loops 169

Summary 169

10 Speed 171

Vectorized Code 171

How to Write Vectorized Code 173

How to Write Fast for Loops in R 178

Vectorized Code in Practice 179

Loops Versus Vectorized Code 183

Summary 183

Project 3 Wrap-up 184

A Installing R and RStudio 187

B R Packages 191

C Updating Rand Its Packages 195

D Loading and Saving Data in R 197

E Debugging R Code 211

Index 221

From the B&N Reads Blog

Customer Reviews