100% found this document useful (2 votes)
11 views

R Programming for Data Science 1st Edition Roger Peng - Download the ebook today to explore every detail

The document promotes a collection of eBooks related to R programming and data science available for download at textbookfull.com. It includes titles such as 'R Programming for Data Science' by Roger Peng and various other advanced programming books by Thomas Mailund. Users can download these eBooks in multiple formats for reading on any device.

Uploaded by

mpungamajzer92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
11 views

R Programming for Data Science 1st Edition Roger Peng - Download the ebook today to explore every detail

The document promotes a collection of eBooks related to R programming and data science available for download at textbookfull.com. It includes titles such as 'R Programming for Data Science' by Roger Peng and various other advanced programming books by Thomas Mailund. Users can download these eBooks in multiple formats for reading on any device.

Uploaded by

mpungamajzer92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Explore the full ebook collection and download it now at textbookfull.

com

R Programming for Data Science 1st Edition Roger


Peng

https://textbookfull.com/product/r-programming-for-data-
science-1st-edition-roger-peng/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

Functional Programming in R: Advanced Statistical


Programming for Data Science, Analysis and Finance 1st
Edition Thomas Mailund
https://textbookfull.com/product/functional-programming-in-r-advanced-
statistical-programming-for-data-science-analysis-and-finance-1st-
edition-thomas-mailund/
textbookfull.com

Advanced Object-Oriented Programming in R: Statistical


Programming for Data Science, Analysis and Finance 1st
Edition Thomas Mailund
https://textbookfull.com/product/advanced-object-oriented-programming-
in-r-statistical-programming-for-data-science-analysis-and-
finance-1st-edition-thomas-mailund/
textbookfull.com

Metaprogramming in R: Advanced Statistical Programming for


Data Science, Analysis and Finance 1st Edition Thomas
Mailund
https://textbookfull.com/product/metaprogramming-in-r-advanced-
statistical-programming-for-data-science-analysis-and-finance-1st-
edition-thomas-mailund/
textbookfull.com

R for Data Science 1st Edition Garrett Grolemund

https://textbookfull.com/product/r-for-data-science-1st-edition-
garrett-grolemund/

textbookfull.com
Programming Skills for Data Science 1st Edition Michael
Freeman

https://textbookfull.com/product/programming-skills-for-data-
science-1st-edition-michael-freeman/

textbookfull.com

Beginning Data Science in R: Data Analysis, Visualization,


and Modelling for the Data Scientist 1st Edition Thomas
Mailund
https://textbookfull.com/product/beginning-data-science-in-r-data-
analysis-visualization-and-modelling-for-the-data-scientist-1st-
edition-thomas-mailund/
textbookfull.com

Functional Data Structures in R: Advanced Statistical


Programming in R Mailund

https://textbookfull.com/product/functional-data-structures-in-r-
advanced-statistical-programming-in-r-mailund/

textbookfull.com

Advanced R: Data Programming and the Cloud 1st Edition


Matt Wiley

https://textbookfull.com/product/advanced-r-data-programming-and-the-
cloud-1st-edition-matt-wiley/

textbookfull.com

Doing Data Science in R An Introduction for Social


Scientists 1st Edition Mark Andrews

https://textbookfull.com/product/doing-data-science-in-r-an-
introduction-for-social-scientists-1st-edition-mark-andrews/

textbookfull.com
R Programming for Data Science
Roger D. Peng
This book is for sale at http://leanpub.com/rprogramming

This version was published on 2019-12-11

This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing
process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and
many iterations to get reader feedback, pivot until you have the right book and build traction once
you do.

© 2014 - 2019 Roger D. Peng


Also By Roger D. Peng
The Art of Data Science
Exploratory Data Analysis with R
Executive Data Science
Report Writing for Data Science in R
Advanced Statistical Computing
The Data Science Salon
Conversations On Data Science
Mastering Software Development in R
Essays on Data Analysis
Contents

1. Stay in Touch! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2. Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

3. History and Overview of R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5


3.1 What is R? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 What is S? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 The S Philosophy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.4 Back to R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.5 Basic Features of R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.6 Free Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.7 Design of the R System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.8 Limitations of R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.9 R Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

4. Getting Started with R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12


4.1 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.2 Getting started with the R interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

5. R Nuts and Bolts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13


5.1 Entering Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.2 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
5.3 R Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
5.4 Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.5 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.6 Creating Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
5.7 Mixing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.8 Explicit Coercion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.9 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.10 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.11 Factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.12 Missing Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
5.13 Data Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5.14 Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
5.15 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
CONTENTS

6. Getting Data In and Out of R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24


6.1 Reading and Writing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.2 Reading Data Files with read.table() . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
6.3 Reading in Larger Datasets with read.table . . . . . . . . . . . . . . . . . . . . . . . . 25
6.4 Calculating Memory Requirements for R Objects . . . . . . . . . . . . . . . . . . . . . 26

7. Using the readr Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

8. Using Textual and Binary Formats for Storing Data . . . . . . . . . . . . . . . . . . . . . . 32


8.1 Using dput() and dump() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
8.2 Binary Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

9. Interfaces to the Outside World . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36


9.1 File Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
9.2 Reading Lines of a Text File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
9.3 Reading From a URL Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

10. Subsetting R Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39


10.1 Subsetting a Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
10.2 Subsetting a Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
10.3 Subsetting Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
10.4 Subsetting Nested Elements of a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
10.5 Extracting Multiple Elements of a List . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
10.6 Partial Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
10.7 Removing NA Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

11. Vectorized Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46


11.1 Vectorized Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

12. Dates and Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48


12.1 Dates in R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
12.2 Times in R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
12.3 Operations on Dates and Times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
12.4 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

13. Managing Data Frames with the dplyr package . . . . . . . . . . . . . . . . . . . . . . . . . 52


13.1 Data Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
13.2 The dplyr Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
13.3 dplyr Grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
13.4 Installing the dplyr package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
13.5 select() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
13.6 filter() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
13.7 arrange() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
13.8 rename() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
13.9 mutate() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
CONTENTS

13.10 group_by() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .60


13.11 %>% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
62
13.12 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

14. Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65


14.1 if-else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
14.2 for Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
14.3 Nested for loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
14.4 while Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
14.5 repeat Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
14.6 next, break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
14.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

15. Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
15.1 Functions in R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
15.2 Your First Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
15.3 Argument Matching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
15.4 Lazy Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
15.5 The ... Argument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
15.6 Arguments Coming After the ... Argument . . . . . . . . . . . . . . . . . . . . . . . 79
15.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

16. Scoping Rules of R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81


16.1 A Diversion on Binding Values to Symbol . . . . . . . . . . . . . . . . . . . . . . . . . 81
16.2 Scoping Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
16.3 Lexical Scoping: Why Does It Matter? . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
16.4 Lexical vs. Dynamic Scoping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
16.5 Application: Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
16.6 Plotting the Likelihood . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
16.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

17. Coding Standards for R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

18. Loop Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93


18.1 Looping on the Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
18.2 lapply() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
18.3 sapply() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
18.4 split() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
18.5 Splitting a Data Frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
18.6 tapply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
18.7 apply() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
18.8 Col/Row Sums and Means . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
18.9 Other Ways to Apply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
18.10 mapply() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
CONTENTS

18.11 Vectorizing a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109


18.12 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

19. Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111


19.1 Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
19.2 Primary R Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
19.3 grep() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
19.4 grepl() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
19.5 regexpr() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
19.6 sub() and gsub() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
19.7 regexec() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
19.8 The stringr Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
19.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

20. Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124


20.1 Something’s Wrong! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
20.2 Figuring Out What’s Wrong . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
20.3 Debugging Tools in R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
20.4 Using traceback() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
20.5 Using debug() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
20.6 Using recover() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
20.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

21. Profiling R Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132


21.1 Using system.time() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
21.2 Timing Longer Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
21.3 The R Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
21.4 Using summaryRprof() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
21.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137

22. Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138


22.1 Generating Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
22.2 Setting the random number seed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
22.3 Simulating a Linear Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
22.4 Random Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
22.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

23. Data Analysis Case Study: Changes in Fine Particle Air Pollution in the U.S. . . . . . . 148
23.1 Synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
23.2 Loading and Processing the Raw Data . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
23.3 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

24. Parallel Computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158


24.1 Hidden Parallelism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
CONTENTS

24.2 Embarrassing Parallelism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160


24.3 The Parallel Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
24.4 Example: Bootstrapping a Statistic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
24.5 Building a Socket Cluster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
24.6 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171

25. Why I Indent My Code 8 Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173

26. About the Author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176


1. Stay in Touch!
Thanks for purchasing this book. If you are interested in hearing more from me about things that
I’m working on (books, data science courses, podcast, etc.), I have a regular podcast called Not So
Standard Deviations¹ that I co-host with Dr. Hilary Parker, a Data Scientist at Stitch Fix. On this
podcast, Hilary and I talk about the craft of data science and discuss common issues and problems
in analyzing data. We’ll also compare how data science is approached in both academia and industry
contexts and discuss the latest industry trends. You can listen to recent episodes on our web page or
you can subscribe to it in iTunes² or your favorite podcasting app.
For those of you who purchased a printed copy of this book, I encourage you to go to the Leanpub
web site and obtain the e-book version³, which is available for free. The reason is that I will
occasionally update the book with new material and readers who purchase the e-book version are
entitled to free updates (this is unfortunately not yet possible with printed books).
Thanks again for purchasing this book and please do stay in touch!
¹http://nssdeviations.com
²https://itunes.apple.com/us/podcast/not-so-standard-deviations/id1040614570
³https://leanpub.com/rprogramming
2. Preface
I started using R in 1998 when I was a college undergraduate working on my senior thesis.
The version was 0.63. I was an applied mathematics major with a statistics concentration and
I was working with Dr. Nicolas Hengartner on an analysis of word frequencies in classic texts
(Shakespeare, Milton, etc.). The idea was to see if we could identify the authorship of each of the
texts based on how frequently they used certain words. We downloaded the data from Project
Gutenberg and used some basic linear discriminant analysis for the modeling. The work was
eventually published¹ and was my first ever peer-reviewed publication. I guess you could argue
it was my first real “data science” experience.
Back then, no one was using R. Most of my classes were taught with Minitab, SPSS, Stata, or
Microsoft Excel. The cool people on the cutting edge of statistical methodology used S-PLUS. I
was working on my thesis late one night and I had a problem. I didn’t have a copy of any of those
software packages because they were expensive and I was a student. I didn’t feel like trekking over
to the computer lab to use the software because it was late at night.
But I had the Internet! After a couple of Yahoo! searches I found a web page for something called R,
which I figured was just a play on the name of the S-PLUS package. From what I could tell, R was a
“clone” of S-PLUS that was free. I had already written some S-PLUS code for my thesis so I figured
I would try to download R and see if I could just run the S-PLUS code.
It didn’t work. At least not at first. It turns out that R is not exactly a clone of S-PLUS and quite a few
modifications needed to be made before the code would run in R. In particular, R was missing a lot of
statistical functionality that had existed in S-PLUS for a long time already. Luckily, R’s programming
language was pretty much there and I was able to more or less re-implement the features that were
missing in R.
After college, I enrolled in a PhD program in statistics at the University of California, Los Angeles.
At the time the department was brand new and they didn’t have a lot of policies or rules (or classes,
for that matter!). So you could kind of do what you wanted, which was good for some students and
not so good for others. The Chair of the department, Jan de Leeuw, was a big fan of XLisp-Stat and
so all of the department’s classes were taught using XLisp-Stat. I diligently bought my copy of Luke
Tierney’s book² and learned to really love XLisp-Stat. It had a number of features that R didn’t have
at all, most notably dynamic graphics.
But ultimately, there were only so many parentheses that I could type, and still all of the research-
level statistics was being done in S-PLUS. The department didn’t really have a lot of copies of S-PLUS
lying around so I turned back to R. When I looked around at my fellow students, I realized that I
was basically the only one who had any experience using R. Since there was a budding interest in R
¹http://amstat.tandfonline.com/doi/abs/10.1198/000313002100#.VQGiSELpagE
²http://www.amazon.com/LISP-STAT-Object-Oriented-Environment-Statistical-Probability/dp/0471509167/
Preface 3

around the department, I decided to start a “brown bag” series where every week for about an hour
I would talk about something you could do in R (which wasn’t much, really). People seemed to like
it, if only because there wasn’t really anyone to turn to if you wanted to learn about R.
By the time I left grad school in 2003, the department had essentially switched over from XLisp-
Stat to R for all its work (although there were a few hold outs). Jan discusses the rationale for the
transition in a paper³ in the Journal of Statistical Software.
In the next step of my career, I went to the Department of Biostatistics⁴ at the Johns Hopkins
Bloomberg School of Public Health, where I have been for the past 16 years. When I got to Johns
Hopkins people already seemed into R. Most people had abandoned S-PLUS a while ago and were
committed to using R for their research. Of all the available statistical packages, R had the most
powerful and expressive programming language, which was perfect for someone developing new
statistical methods.
However, we didn’t really have a class that taught students how to use R. This was a problem because
most of our grad students were coming into the program having never heard of R. Most likely in
their undergraduate programs, they used some other software package. So along with Rafael Irizarry,
Brian Caffo, Ingo Ruczinski, and Karl Broman, I started a new class to teach our graduate students
R and a number of other skills they’d need in grad school.
The class was basically a weekly seminar where one of us talked about a computing topic of interest.
I gave some of the R lectures in that class and when I asked people who had heard of R before, almost
no one raised their hand. And no one had actually used it before. The main selling point at the time
was “It’s just like S-PLUS but it’s free!” A lot of people had experience with SAS or Stata or SPSS.
A number of people had used something like Java or C/C++ before and so I often used that as a
reference frame. No one had ever used a functional-style of programming language like Scheme or
Lisp.
To this day, I still teach the class, known a Biostatistics 140.776 (“Statistical Computing”). However,
the nature of the class has changed quite a bit over the years. The population of students (mostly
first-year graduate students) has shifted to the point where many of them have been introduced to R
as undergraduates. This trend mirrors the overall trend with statistics where we are seeing more and
more students do undergraduate majors in statistics (as opposed to, say, mathematics). Eventually,
by 2008–2009, when I’d asked how many people had heard of or used R before, everyone raised
their hand. However, even at that late date, I still felt the need to convince people that R was a “real”
language that could be used for real tasks.
R has grown a lot in recent years, and is being used in so many places now, that I think it’s
essentially impossible for a person to keep track of everything that is going on. That’s fine, but
it makes “introducing” people to R an interesting experience. Nowadays in class, students are often
teaching me something new about R that I’ve never seen or heard of before (they are quite good
at Googling around for themselves). I feel no need to “bring people over” to R. In fact it’s quite the
opposite–people might start asking questions if I weren’t teaching R.
³http://www.jstatsoft.org/v13/i07
⁴http://www.biostat.jhsph.edu
Preface 4

This book comes from my experience teaching R in a variety of settings and through different stages
of its (and my) development. Much of the material has been taken from by Statistical Computing
class as well as the R Programming⁵ class I teach through Coursera.
I’m looking forward to teaching R to people as long as people will let me, and I’m interested in
seeing how the next generation of students will approach it (and how my approach to them will
change). Overall, it’s been just an amazing experience to see the widespread adoption of R over the
past decade. I’m sure the next decade will be just as amazing.
⁵https://www.coursera.org/course/rprog
3. History and Overview of R
There are only two kinds of languages: the ones people complain about and the ones
nobody uses —Bjarne Stroustrup

Watch a video of this chapter¹

3.1 What is R?
This is an easy question to answer. R is a dialect of S.

3.2 What is S?
S is a language that was developed by John Chambers and others at the old Bell Telephone
Laboratories, originally part of AT&T Corp. S was initiated in 1976² as an internal statistical analysis
environment—originally implemented as Fortran libraries. Early versions of the language did not
even contain functions for statistical modeling.
In 1988 the system was rewritten in C and began to resemble the system that we have today (this
was Version 3 of the language). The book Statistical Models in S by Chambers and Hastie (the white
book) documents the statistical analysis functionality. Version 4 of the S language was released in
1998 and is the version we use today. The book Programming with Data by John Chambers (the
green book) documents this version of the language.
Since the early 90’s the life of the S language has gone down a rather winding path. In 1993 Bell Labs
gave StatSci (later Insightful Corp.) an exclusive license to develop and sell the S language. In 2004
Insightful purchased the S language from Lucent for $2 million. In 2006, Alcatel purchased Lucent
Technologies and is now called Alcatel-Lucent.
Insightful sold its implementation of the S language under the product name S-PLUS and built a
number of fancy features (GUIs, mostly) on top of it—hence the “PLUS”. In 2008 Insightful was
acquired by TIBCO for $25 million. As of this writing TIBCO is the current owner of the S language
and is its exclusive developer.
The fundamentals of the S language itself has not changed dramatically since the publication of the
Green Book by John Chambers in 1998. In 1998, S won the Association for Computing Machinery’s
Software System Award, a highly prestigious award in the computer science field.
¹https://youtu.be/STihTnVSZnI
²http://cm.bell-labs.com/stat/doc/94.11.ps
History and Overview of R 6

3.3 The S Philosophy


The general S philosophy is important to understand for users of S and R because it sets the stage for
the design of the language itself, which many programming veterans find a bit odd and confusing.
In particular, it’s important to realize that the S language had its roots in data analysis, and did not
come from a traditional programming language background. Its inventors were focused on figuring
out how to make data analysis easier, first for themselves, and then eventually for others.
In Stages in the Evolution of S³, John Chambers writes:

“[W]e wanted users to be able to begin in an interactive environment, where they did not
consciously think of themselves as programming. Then as their needs became clearer and
their sophistication increased, they should be able to slide gradually into programming,
when the language and system aspects would become more important.”

The key part here was the transition from user to developer. They wanted to build a language that
could easily service both “people”. More technically, they needed to build language that would
be suitable for interactive data analysis (more command-line based) as well as for writing longer
programs (more traditional programming language-like).

3.4 Back to R
The R language came to use quite a bit after S had been developed. One key limitation of the S
language was that it was only available in a commericial package, S-PLUS. In 1991, R was created
by Ross Ihaka and Robert Gentleman in the Department of Statistics at the University of Auckland. In
1993 the first announcement of R was made to the public. Ross’s and Robert’s experience developing
R is documented in a 1996 paper in the Journal of Computational and Graphical Statistics:

Ross Ihaka and Robert Gentleman. R: A language for data analysis and graphics. Journal
of Computational and Graphical Statistics, 5(3):299–314, 1996

In 1995, Martin Mächler made an important contribution by convincing Ross and Robert to use the
GNU General Public License⁴ to make R free software. This was critical because it allowed for the
source code for the entire R system to be accessible to anyone who wanted to tinker with it (more
on free software later).
In 1996, a public mailing list was created (the R-help and R-devel lists) and in 1997 the R Core
Group was formed, containing some people associated with S and S-PLUS. Currently, the core group
controls the source code for R and is solely able to check in changes to the main R source tree. Finally,
in 2000 R version 1.0.0 was released to the public.
³http://www.stat.bell-labs.com/S/history.html
⁴http://www.gnu.org/licenses/gpl-2.0.html
History and Overview of R 7

3.5 Basic Features of R


In the early days, a key feature of R was that its syntax is very similar to S, making it easy for
S-PLUS users to switch over. While the R’s syntax is nearly identical to that of S’s, R’s semantics,
while superficially similar to S, are quite different. In fact, R is technically much closer to the Scheme
language than it is to the original S language when it comes to how R works under the hood.
Today R runs on almost any standard computing platform and operating system. Its open source
nature means that anyone is free to adapt the software to whatever platform they choose. Indeed, R
has been reported to be running on modern tablets, phones, PDAs, and game consoles.
One nice feature that R shares with many popular open source projects is frequent releases. These
days there is a major annual release, typically in October, where major new features are incorporated
and released to the public. Throughout the year, smaller-scale bugfix releases will be made as needed.
The frequent releases and regular release cycle indicates active development of the software and
ensures that bugs will be addressed in a timely manner. Of course, while the core developers control
the primary source tree for R, many people around the world make contributions in the form of new
feature, bug fixes, or both.
Another key advantage that R has over many other statistical packages (even today) is its sophisti-
cated graphics capabilities. R’s ability to create “publication quality” graphics has existed since the
very beginning and has generally been better than competing packages. Today, with many more
visualization packages available than before, that trend continues. R’s base graphics system allows
for very fine control over essentially every aspect of a plot or graph. Other newer graphics systems,
like lattice and ggplot2 allow for complex and sophisticated visualizations of high-dimensional data.
R has maintained the original S philosophy, which is that it provides a language that is both useful
for interactive work, but contains a powerful programming language for developing new tools. This
allows the user, who takes existing tools and applies them to data, to slowly but surely become a
developer who is creating new tools.
Finally, one of the joys of using R has nothing to do with the language itself, but rather with the
active and vibrant user community. In many ways, a language is successful inasmuch as it creates a
platform with which many people can create new things. R is that platform and thousands of people
around the world have come together to make contributions to R, to develop packages, and help
each other use R for all kinds of applications. The R-help and R-devel mailing lists have been highly
active for over a decade now and there is considerable activity on web sites like Stack Overflow.

3.6 Free Software


A major advantage that R has over many other statistical packages and is that it’s free in the sense
of free software (it’s also free in the sense of free beer). The copyright for the primary source code
for R is held by the R Foundation⁵ and is published under the GNU General Public License version
⁵http://www.r-project.org/foundation/
History and Overview of R 8

2.0⁶.
According to the Free Software Foundation, with free software, you are granted the following four
freedoms⁷

• The freedom to run the program, for any purpose (freedom 0).
• The freedom to study how the program works, and adapt it to your needs (freedom 1). Access
to the source code is a precondition for this.
• The freedom to redistribute copies so you can help your neighbor (freedom 2).
• The freedom to improve the program, and release your improvements to the public, so that the
whole community benefits (freedom 3). Access to the source code is a precondition for this.

You can visit the Free Software Foundation’s web site⁸ to learn a lot more about free software. The
Free Software Foundation was founded by Richard Stallman in 1985 and Stallman’s personal web
site⁹ is an interesting read if you happen to have some spare time.

3.7 Design of the R System


The primary R system is available from the Comprehensive R Archive Network¹⁰, also known as
CRAN. CRAN also hosts many add-on packages that can be used to extend the functionality of R.
The R system is divided into 2 conceptual parts:

1. The “base” R system that you download from CRAN: Linux¹¹ Windows¹² Mac¹³ Source Code¹⁴
2. Everything else.

R functionality is divided into a number of packages.

• The “base” R system contains, among other things, the base package which is required to run
R and contains the most fundamental functions.
• The other packages contained in the “base” system include utils, stats, datasets, graphics,
grDevices, grid, methods, tools, parallel, compiler, splines, tcltk, stats4.
• There are also “Recommended” packages: boot, class, cluster, codetools, foreign, KernS-
mooth, lattice, mgcv, nlme, rpart, survival, MASS, spatial, nnet, Matrix.
⁶http://www.gnu.org/licenses/gpl-2.0.html
⁷http://www.gnu.org/philosophy/free-sw.html
⁸http://www.fsf.org
⁹https://stallman.org
¹⁰http://cran.r-project.org
¹¹http://cran.r-project.org/bin/linux/
¹²http://cran.r-project.org/bin/windows/
¹³http://cran.r-project.org/bin/macosx/
¹⁴http://cran.r-project.org/src/base/R-3/R-3.1.3.tar.gz
History and Overview of R 9

When you download a fresh installation of R from CRAN, you get all of the above, which represents
a substantial amount of functionality. However, there are many other packages available:

• There are over 4000 packages on CRAN that have been developed by users and programmers
around the world.
• There are also many packages associated with the Bioconductor project¹⁵.
• People often make packages available on their personal websites; there is no reliable way to
keep track of how many packages are available in this fashion.
• There are a number of packages being developed on repositories like GitHub and BitBucket but
there is no reliable listing of all these packages.

3.8 Limitations of R
No programming language or statistical analysis system is perfect. R certainly has a number of
drawbacks. For starters, R is essentially based on almost 50 year old technology, going back to the
original S system developed at Bell Labs. There was originally little built in support for dynamic or
3-D graphics (but things have improved greatly since the “old days”).
Another commonly cited limitation of R is that objects must generally be stored in physical memory.
This is in part due to the scoping rules of the language, but R generally is more of a memory hog
than other statistical packages. However, there have been a number of advancements to deal with
this, both in the R core and also in a number of packages developed by contributors. Also, computing
power and capacity has continued to grow over time and amount of physical memory that can be
installed on even a consumer-level laptop is substantial. While we will likely never have enough
physical memory on a computer to handle the increasingly large datasets that are being generated,
the situation has gotten quite a bit easier over time.
At a higher level one “limitation” of R is that its functionality is based on consumer demand and
(voluntary) user contributions. If no one feels like implementing your favorite method, then it’s your
job to implement it (or you need to pay someone to do it). The capabilities of the R system generally
reflect the interests of the R user community. As the community has ballooned in size over the past
10 years, the capabilities have similarly increased. When I first started using R, there was very little
in the way of functionality for the physical sciences (physics, astronomy, etc.). However, now some
of those communities have adopted R and we are seeing more code being written for those kinds of
applications.
If you want to know my general views on the usefulness of R, you can see them here in the following
exchange on the R-help mailing list with Douglas Bates and Brian Ripley in June 2004:

Roger D. Peng: I don’t think anyone actually believes that R is designed to make everyone
happy. For me, R does about 99% of the things I need to do, but sadly, when I need to order
a pizza, I still have to pick up the telephone.
¹⁵http://bioconductor.org
History and Overview of R 10

Douglas Bates: There are several chains of pizzerias in the U.S. that provide for Internet-
based ordering (e.g. www.papajohnsonline.com) so, with the Internet modules in R, it’s
only a matter of time before you will have a pizza-ordering function available.

Brian D. Ripley: Indeed, the GraphApp toolkit (used for the RGui interface under R for
Windows, but Guido forgot to include it) provides one (for use in Sydney, Australia, we
presume as that is where the GraphApp author hails from). Alternatively, a Padovian has
no need of ordering pizzas with both home and neighbourhood restaurants ….

At this point in time, I think it would be fairly straightforward to build a pizza ordering R package
using something like the RCurl or httr packages. Any takers?

3.9 R Resources

Official Manuals
As far as getting started with R by reading stuff, there is of course this book. Also, available from
CRAN¹⁶ are

• An Introduction to R¹⁷
• R Data Import/Export¹⁸
• Writing R Extensions¹⁹: Discusses how to write and organize R packages
• R Installation and Administration²⁰: This is mostly for building R from the source code)
• R Internals²¹: This manual describes the low level structure of R and is primarily for developers
and R core members
• R Language Definition²²: This documents the R language and, again, is primarily for developers

Useful Standard Texts on S and R


• Chambers (2008). Software for Data Analysis, Springer
• Chambers (1998). Programming with Data, Springer: This book is not about R, but it describes
the organization and philosophy of the current version of the S language, and is a useful
reference.
• Venables & Ripley (2002). Modern Applied Statistics with S, Springer: This is a standard textbook
in statistics and describes how to use many statistical methods in R. This book has an associated
R package (the MASS package) that comes with every installation of R.
¹⁶http://cran.r-project.org
¹⁷http://cran.r-project.org/doc/manuals/r-release/R-intro.html
¹⁸http://cran.r-project.org/doc/manuals/r-release/R-data.html
¹⁹http://cran.r-project.org/doc/manuals/r-release/R-exts.html
²⁰http://cran.r-project.org/doc/manuals/r-release/R-admin.html
²¹http://cran.r-project.org/doc/manuals/r-release/R-ints.html
²²http://cran.r-project.org/doc/manuals/r-release/R-lang.html
History and Overview of R 11

• Venables & Ripley (2000). S Programming, Springer: This book is a little old but is still relevant
and accurate. Despite its title, this book is useful for R also.
• Murrell (2005). R Graphics, Chapman & Hall/CRC Press: Paul Murrell wrote and designed much
of the graphics system in R and this book essentially documents the underlying details. This
is not so much a “user-level” book as a developer-level book. But it is an important book for
anyone interested in designing new types of graphics or visualizations.
• Wickham (2014). Advanced R, Chapman & Hall/CRC Press: This book by Hadley Wickham
covers a number of areas including object-oriented programming, functional programming,
profiling and other advanced topics.

Other Resources
• Major technical publishers like Springer, Chapman & Hall/CRC have entire series of books
dedicated to using R in various applications. For example, Springer has a series of books called
Use R!.
• A longer list of books can be found on the CRAN web site²³.

²³http://www.r-project.org/doc/bib/R-books.html
4. Getting Started with R
4.1 Installation
The first thing you need to do to get started with R is to install it on your computer. R works on
pretty much every platform available, including the widely available Windows, Mac OS X, and Linux
systems. If you want to watch a step-by-step tutorial on how to install R for Mac or Windows, you
can watch these videos:

• Installing R on Windows¹
• Installing R on the Mac²

There is also an integrated development environment available for R that is built by RStudio. I really
like this IDE—it has a nice editor with syntax highlighting, there is an R object viewer, and there are
a number of other nice features that are integrated. You can see how to install RStudio here

• Installing RStudio³

The RStudio IDE is available from RStudio’s web site⁴.

4.2 Getting started with the R interface


After you install R you will need to launch it and start writing R code. Before we get to exactly how
to write R code, it’s useful to get a sense of how the system is organized. In these two videos I talk
about where to write code and how set your working directory, which let’s R know where to find
all of your files.

• Writing code and setting your working directory on the Mac⁵


• Writing code and setting your working directory on Windows⁶

¹http://youtu.be/Ohnk9hcxf9M
²https://youtu.be/uxuuWXU-7UQ
³https://youtu.be/bM7Sfz-LADM
⁴http://rstudio.com
⁵https://youtu.be/8xT3hmJQskU
⁶https://youtu.be/XBcvH1BpIBo
5. R Nuts and Bolts
5.1 Entering Input
Watch a video of this section¹
At the R prompt we type expressions. The <- symbol is the assignment operator.

> x <- 1
> print(x)
[1] 1
> x
[1] 1
> msg <- "hello"

The grammar of the language determines whether an expression is complete or not.

x <- ## Incomplete expression

The # character indicates a comment. Anything to the right of the # (including the # itself) is ignored.
This is the only comment character in R. Unlike some other languages, R does not support multi-line
comments or comment blocks.

5.2 Evaluation
When a complete expression is entered at the prompt, it is evaluated and the result of the evaluated
expression is returned. The result may be auto-printed.

> x <- 5 ## nothing printed


> x ## auto-printing occurs
[1] 5
> print(x) ## explicit printing
[1] 5

The [1] shown in the output indicates that x is a vector and 5 is its first element.
Typically with interactive work, we do not explicitly print objects with the print function; it is much
easier to just auto-print them by typing the name of the object and hitting return/enter. However,
¹https://youtu.be/vGY5i_J2c-c?t=4m43s
R Nuts and Bolts 14

when writing scripts, functions, or longer programs, there is sometimes a need to explicitly print
objects because auto-printing does not work in those settings.
When an R vector is printed you will notice that an index for the vector is printed in square brackets
[] on the side. For example, see this integer sequence of length 20.

> x <- 11:30


> x
[1] 11 12 13 14 15 16 17 18 19 20 21 22
[13] 23 24 25 26 27 28 29 30

The numbers in the square brackets are not part of the vector itself, they are merely part of the
printed output.
With R, it’s important that one understand that there is a difference between the actual R object
and the manner in which that R object is printed to the console. Often, the printed output may have
additional bells and whistles to make the output more friendly to the users. However, these bells and
whistles are not inherently part of the object.
Note that the : operator is used to create integer sequences.

5.3 R Objects
Watch a video of this section²
R has five basic or “atomic” classes of objects:

• character
• numeric (real numbers)
• integer
• complex
• logical (True/False)

The most basic type of R object is a vector. Empty vectors can be created with the vector() function.
There is really only one rule about vectors in R, which is that A vector can only contain objects
of the same class.
But of course, like any good rule, there is an exception, which is a list, which we will get to a bit later.
A list is represented as a vector but can contain objects of different classes. Indeed, that’s usually
why we use them.
There is also a class for “raw” objects, but they are not commonly used directly in data analysis and
I won’t cover them here.
²https://youtu.be/vGY5i_J2c-c
R Nuts and Bolts 15

5.4 Numbers
Numbers in R are generally treated as numeric objects (i.e. double precision real numbers). This
means that even if you see a number like “1” or “2” in R, which you might think of as integers, they
are likely represented behind the scenes as numeric objects (so something like “1.00” or “2.00”). This
isn’t important most of the time…except when it is.
If you explicitly want an integer, you need to specify the L suffix. So entering 1 in R gives you a
numeric object; entering 1L explicitly gives you an integer object.
There is also a special number Inf which represents infinity. This allows us to represent entities like
1 / 0. This way, Inf can be used in ordinary calculations; e.g. 1 / Inf is 0.

The value NaN represents an undefined value (“not a number”); e.g. 0 / 0; NaN can also be thought of
as a missing value (more on that later)

5.5 Attributes
R objects can have attributes, which are like metadata for the object. These metadata can be very
useful in that they help to describe the object. For example, column names on a data frame help to
tell us what data are contained in each of the columns. Some examples of R object attributes are

• names, dimnames
• dimensions (e.g. matrices, arrays)
• class (e.g. integer, numeric)
• length
• other user-defined attributes/metadata

Attributes of an object (if any) can be accessed using the attributes() function. Not all R objects
contain attributes, in which case the attributes() function returns NULL.

5.6 Creating Vectors


Watch a video of this section³
The c() function can be used to create vectors of objects by concatenating things together.

³https://youtu.be/w8_XdYI3reU
R Nuts and Bolts 16

> x <- c(0.5, 0.6) ## numeric


> x <- c(TRUE, FALSE) ## logical
> x <- c(T, F) ## logical
> x <- c("a", "b", "c") ## character
> x <- 9:29 ## integer
> x <- c(1+0i, 2+4i) ## complex

Note that in the above example, T and F are short-hand ways to specify TRUE and FALSE. However,
in general one should try to use the explicit TRUE and FALSE values when indicating logical values.
The T and F values are primarily there for when you’re feeling lazy.
You can also use the vector() function to initialize vectors.

> x <- vector("numeric", length = 10)


> x
[1] 0 0 0 0 0 0 0 0 0 0

5.7 Mixing Objects


There are occasions when different classes of R objects get mixed together. Sometimes this happens
by accident but it can also happen on purpose. So what happens with the following code?

> y <- c(1.7, "a") ## character


> y <- c(TRUE, 2) ## numeric
> y <- c("a", TRUE) ## character

In each case above, we are mixing objects of two different classes in a vector. But remember that
the only rule about vectors says this is not allowed. When different objects are mixed in a vector,
coercion occurs so that every element in the vector is of the same class.
In the example above, we see the effect of implicit coercion. What R tries to do is find a way to
represent all of the objects in the vector in a reasonable fashion. Sometimes this does exactly what
you want and…sometimes not. For example, combining a numeric object with a character object
will create a character vector, because numbers can usually be easily represented as strings.

5.8 Explicit Coercion


Objects can be explicitly coerced from one class to another using the as.* functions, if available.
R Nuts and Bolts 17

> x <- 0:6


> class(x)
[1] "integer"
> as.numeric(x)
[1] 0 1 2 3 4 5 6
> as.logical(x)
[1] FALSE TRUE TRUE TRUE TRUE TRUE TRUE
> as.character(x)
[1] "0" "1" "2" "3" "4" "5" "6"

Sometimes, R can’t figure out how to coerce an object and this can result in NAs being produced.

> x <- c("a", "b", "c")


> as.numeric(x)
Warning: NAs introduced by coercion
[1] NA NA NA
> as.logical(x)
[1] NA NA NA
> as.complex(x)
Warning: NAs introduced by coercion
[1] NA NA NA

When nonsensical coercion takes place, you will usually get a warning from R.

5.9 Matrices
Matrices are vectors with a dimension attribute. The dimension attribute is itself an integer vector
of length 2 (number of rows, number of columns)

> m <- matrix(nrow = 2, ncol = 3)


> m
[,1] [,2] [,3]
[1,] NA NA NA
[2,] NA NA NA
> dim(m)
[1] 2 3
> attributes(m)
$dim
[1] 2 3

Matrices are constructed column-wise, so entries can be thought of starting in the “upper left” corner
and running down the columns.
R Nuts and Bolts 18

> m <- matrix(1:6, nrow = 2, ncol = 3)


> m
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6

Matrices can also be created directly from vectors by adding a dimension attribute.

> m <- 1:10


> m
[1] 1 2 3 4 5 6 7 8 9 10
> dim(m) <- c(2, 5)
> m
[,1] [,2] [,3] [,4] [,5]
[1,] 1 3 5 7 9
[2,] 2 4 6 8 10

Matrices can be created by column-binding or row-binding with the cbind() and rbind() functions.

> x <- 1:3


> y <- 10:12
> cbind(x, y)
x y
[1,] 1 10
[2,] 2 11
[3,] 3 12
> rbind(x, y)
[,1] [,2] [,3]
x 1 2 3
y 10 11 12

5.10 Lists
Lists are a special type of vector that can contain elements of different classes. Lists are a very
important data type in R and you should get to know them well. Lists, in combination with the
various “apply” functions discussed later, make for a powerful combination.
Lists can be explicitly created using the list() function, which takes an arbitrary number of
arguments.
R Nuts and Bolts 19

> x <- list(1, "a", TRUE, 1 + 4i)


> x
[[1]]
[1] 1

[[2]]
[1] "a"

[[3]]
[1] TRUE

[[4]]
[1] 1+4i

We can also create an empty list of a prespecified length with the vector() function

> x <- vector("list", length = 5)


> x
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

[[4]]
NULL

[[5]]
NULL

5.11 Factors
Watch a video of this section⁴
Factors are used to represent categorical data and can be unordered or ordered. One can think of
a factor as an integer vector where each integer has a label. Factors are important in statistical
modeling and are treated specially by modelling functions like lm() and glm().
Using factors with labels is better than using integers because factors are self-describing. Having a
variable that has values “Male” and “Female” is better than a variable that has values 1 and 2.
Factor objects can be created with the factor() function.
⁴https://youtu.be/NuY6jY4qE7I
R Nuts and Bolts 20

> x <- factor(c("yes", "yes", "no", "yes", "no"))


> x
[1] yes yes no yes no
Levels: no yes
> table(x)
x
no yes
2 3
> ## See the underlying representation of factor
> unclass(x)
[1] 2 2 1 2 1
attr(,"levels")
[1] "no" "yes"

Often factors will be automatically created for you when you read a dataset in using a function like
read.table(). Those functions often default to creating factors when they encounter data that look
like characters or strings.
The order of the levels of a factor can be set using the levels argument to factor(). This can be
important in linear modelling because the first level is used as the baseline level.

> x <- factor(c("yes", "yes", "no", "yes", "no"))


> x ## Levels are put in alphabetical order
[1] yes yes no yes no
Levels: no yes
> x <- factor(c("yes", "yes", "no", "yes", "no"),
+ levels = c("yes", "no"))
> x
[1] yes yes no yes no
Levels: yes no

5.12 Missing Values


Missing values are denoted by NA or NaN for q undefined mathematical operations.

• is.na() is used to test objects if they are NA


• is.nan() is used to test for NaN
• NA values have a class also, so there are integer NA, character NA, etc.
• A NaN value is also NA but the converse is not true
R Nuts and Bolts 21

> ## Create a vector with NAs in it


> x <- c(1, 2, NA, 10, 3)
> ## Return a logical vector indicating which elements are NA
> is.na(x)
[1] FALSE FALSE TRUE FALSE FALSE
> ## Return a logical vector indicating which elements are NaN
> is.nan(x)
[1] FALSE FALSE FALSE FALSE FALSE

> ## Now create a vector with both NA and NaN values


> x <- c(1, 2, NaN, NA, 4)
> is.na(x)
[1] FALSE FALSE TRUE TRUE FALSE
> is.nan(x)
[1] FALSE FALSE TRUE FALSE FALSE

5.13 Data Frames


Data frames are used to store tabular data in R. They are an important type of object in R and
are used in a variety of statistical modeling applications. Hadley Wickham’s package dplyr⁵ has an
optimized set of functions designed to work efficiently with data frames.
Data frames are represented as a special type of list where every element of the list has to have the
same length. Each element of the list can be thought of as a column and the length of each element
of the list is the number of rows.
Unlike matrices, data frames can store different classes of objects in each column. Matrices must
have every element be the same class (e.g. all integers or all numeric).
In addition to column names, indicating the names of the variables or predictors, data frames have
a special attribute called row.names which indicate information about each row of the data frame.
Data frames are usually created by reading in a dataset using the read.table() or read.csv().
However, data frames can also be created explicitly with the data.frame() function or they can be
coerced from other types of objects like lists.
Data frames can be converted to a matrix by calling data.matrix(). While it might seem that the
as.matrix() function should be used to coerce a data frame to a matrix, almost always, what you
want is the result of data.matrix().

⁵https://github.com/hadley/dplyr
Another Random Document on
Scribd Without Any Related Topics
considerable amount of leg-spin, would be gradually working away to the
batsman’s off-side every inch of its journey, both before and after pitching.”
Such a break would be liable to lead to a catch at the wicket or in the
slips. It is especially useful in school cricket. School bowlers—and others—
should acquire this action. It is not difficult or exhausting, but it needs a
careful study of field-placing on the on-side.
(4.) To the break given by arm, wrist, and fingers, we may now add the
curl, which some bowlers have or occasionally have, but which few if any
bowlers know how to teach. The following remarks about the American
baseball-pitcher’s curl in the air, produced by a throw, are worth studying.
They are from Mr. Walter Camp’s “Book of College Sports.” I think I am
right in saying that the American curve usually does not come till towards
the end of the ball’s flight.
“The easiest curve, and the one to be acquired first, is the out-curve. The
simplest method is to take the ball in the hand between the extended thumb
and the first and second fingers, the third and little fingers being closed. The
ball rests against the (side of the) middle part of the third finger, but is
firmly clasped by the first two and the thumb. If the arm be then extended
horizontally from the shoulder, with the palm of the hand up, it will be seen
that if the ball were spun like a top by the two fingers and thumb it would
turn in the way indicated by the arrow in the diagram. This is the way it
must twist to accomplish the out-curve. The simpler way to impart this twist
is not the spinning motion, but rather a snap as the ball is leaving the
fingers, performed almost entirely without the aid of the thumb. The
sensation is that of throwing the ball hard, but dragging it back with the
ends and sides of the fingers just as it leaves the hand.” For further
instructions the reader should consult this excellent work, published by the
Century Company of New York.
The writer goes on to remark:—
“The most logical explanation of the curvature of a ball depends upon
the supposition of the compression of the air just in front of the ball and a
corresponding rarefaction immediately behind it, so that the ball by its
friction is deflected from its true course.”
It is interesting to notice that, in contrast with our “batting versus
bowling” problem, “in spite of all restrictions, such is the growing skill of
pitchers that the problem is constantly under discussion how to legislate in
favour of the batsmen.”
(5.) Additional curl or break may be added by the wind, slope of the
ground, and so on.
In all cases, the break must be given especially at the last moment, and
must not be expended in the previous action, unless the object be to deceive
the batsman. Obviously one should not always put on the same amount of
break; one should appear to do so. A straight ball following many breaks
from the off is apt to be very effective.
Now as to the learning of the break, two or three notions seem to me
sheer common sense.
(1.) The muscles of the various mechanisms, and especially of the wrist
and fingers, must be exercised in various ways: by full extensions in
different directions, by full contractions, by partial movements in different
directions, and so on. A certain amount of strength is needed, but let
litheness not be sacrificed.
(2.) Underhand bowling of breaks in either direction not only exercises
these mechanisms, and makes them habitual and easy, but it also shows
effects very clearly. Stump-cricket with an indiarubber ball and underhand
bowling is good training for the bowler’s break as well as for the batsman’s
straight bat.
(3.) Slow bowling is fine for the same reasons. During it the ball is held
longer in the fingers; after it the ball is “held” longer by the ground. Hence
it also shows its effects clearly and encourages the beginner. Moreover, the
slow breaking ball is useful as a change for the medium-paced bowler.
Some of the break thus acquired as an easy habit may be transferred to
medium or fast bowling.
Concealment is of the utmost importance. The extra Commandment,
“Thou shalt not be found out,” is of great moment when once the bowler
has control of the ball’s flight and spin.
To hide direction is hard, unless the curl be used. To hide length and
pace, as Shaw, Spofforth, Lohmann and others used to, is easier: one or two
helps have been offered above. We may notice that Shaw used to alter the
height of his hand: this had several important results; for example, the low
delivery made the ball bump less and “skim” more. Shaw again would bowl
a very effectively concealed variety, a ball rather shorter, rather slower,
rather higher. A great change is not usually so effective as a small one,
except when a very slow or medium bowler occasionally bowls a very fast
ball. In masking these changes, as well as the break, the bowler needs what

XXVII.—Bowler waiting for ball to be thrown in: he is standing well back from the
wicket.
[To face page 91.

Mr. A. G. Steel alludes to as the wiliness of the serpent with the apparent
harmlessness of the dove. He needs complete mastery of this or that part of
the mechanism by itself, so that he may or may not turn his wrist or fingers
at the last moment either completely or partially, but anyhow “with intent to
deceive.” Need a skilful bowler be a skilful liar?
The art of taking balls at the wicket, like the art of fielding balls,
demands a rapid recovery of balance. After his effort the bowler must either
field the ball or else get ready with his wicket between himself and the
fielder. As the photograh (XXVII.) of Hirst shows, he should not stand too
near the wicket, for it is easier to move forward than to move back. He must
also be prepared for a bad throw, either too high or else too low—perhaps a
half-volley or what would be to a batsman a “good length” ball.
The “Badminton Volume” gives this useful advice:—“A golden rule for
every bowler to observe is—after the batsman has played the ball, get back
to the wicket as quickly as possible. Neglect of this rule loses many a ‘run-
out.’ If a bowler does not get back to his wicket, there is no one to take the
ball and knock the bails off should the batsman run and the ball be returned
to the bowler’s end. When the ball is thrown up, the bowler should not take
it till it has just passed the wicket; he should then seize and sweep the ball
into the stumps in one and the same action.”
For the purpose of taking the ball and putting down the wicket rapidly—
in fact almost by a single movement—he cannot do better than practise
wicket-keeping now and then. This should give him hints for bowling also.
It should help him to keep his real eye on the ball and his imaginary eye, his
mind’s eye, on imaginary wickets. He must sense by imagination, and by
“feel,” precisely where the wickets are, just as at Tennis. I have to sense
where the “Grille” or “Dedans” is, even while my real outward eye is on the
ball.
The bowler, like the wicket-keeper, should be an adviser (but with
judgment and tact) to the captain, especially with regard to the throwing in
and backing up by this or that fielder, and the correct placing of all the
fielders, which must depend on circumstances and individual batsmen. This
has brought us to more general remarks on bowling.

GENERAL HINTS.
The first and foremost piece of advice to the would-be bowler, that is to
say to every cricketer, is to read what the great authorities, Messrs. A. G.
Steel, Ranjitsinhji, Grace, the Lytteltons, and others say about the
importance of bowling, and of learning to bowl well or better, not only for
the sake of the game’s future and of the team’s success, but also for the sake
of personal enjoyment. Let the reader digest what Mr. Edward Lyttelton
says about practice in the bedroom, and what Mr. C. B. Fry (in the “Strand”
for July, 1902) says about the helps which he used to his grand athletic
success—for instance, kicking a small ball in a courtyard, and jumping over
an arm-chair. Let every cricketer read how the Americans train for baseball.
Then let him not despise the mastering of the mechanism in his bedroom or
elsewhere, if possible before a large looking-glass. There should be one or
two in every pavilion.
The following advice is not new, but it will all bear repetition. No
amount of honest care spent in suggestions about bowling can be
considered as wasted. The future of enjoyable cricket lies largely with
improvement in bowling.
Be able to bowl round as well as over the wicket, for such a change of
starting-point is almost as good as a change of action. In view of what
certain Americans have achieved in Philadelphia and elsewhere by being
taught the use of the left side (for drawing, modelling, etc.) in early
childhood, I do not hesitate to say, learn to bowl fairly well with the left
hand as well as with the right. The control of the left side would add power
to batting and fielding even if it led to little success in actual bowling.
When you have got the direction and can bowl persistently to the off,
practise the straight and fast yorker as well as the good length ball to the
off. In fact, practise intentional variety; do not rely on the variety which is
incidental to careless and “undisciplined” bowling.
You must have firm feet—the left foot must have nails that bite the
ground well, especially near the boot’s toe; you must have strong hands—
they may be hardened by salt, etc., or, in case of sore places, may be
protected by adhesive plaister round the finger or hand (this prevents
painful friction). Sprains may be treated by water or massage or radiant
light and heat.
Having attended to such things, study pitches—their soft or hard spots,
the trees, etc., behind the bowler’s arm, the direction of the sun, of the wind
—in fact, all details that a careful general must notice. Spofforth used to
make a point of finding out “the pace of the wicket, even if his first effort
cost him dear.” One or two balls just off the pitch, before play begins, may
save such runs. Don’t bowl these or the early ones too fast; the Public
School Racquet representatives at Queen’s slash about from the very
moment that they enter the court. This is silly. Start gently; increase the
severity by degrees.
At the beginning of an innings or of a new batsman’s innings pitch the
ball well up. A yorker is among the most effective attacks (except to W. G.
and a few others); even a half-volley is often useful, or a full-pitch on the
body, but not a long hop.
Correct your mistakes of direction, length, and so on, by exaggerating a
little in the opposite direction.
To a slogger a straight ball—unless it be a yorker—is not the best, as a
rule, especially if he runs out; a ball to the off may be most useful, for a
slogger generally runs out straight down the pitch rather than towards the
side (in which case he would turn an off-ball into a straight ball). With W.
G.’s action round the wicket, a ball on the leg-side may be just the thing. A
break to the off is generally needed, so as to tempt a catch to cover or third
man.
Do not mind having your “head-balls” hit. Mr. A. G. Steel’s words must
be borne in mind constantly, at least for ordinary occasions when the main
object is not to keep the runs down. He says:—“When a bowler is put on to
bowl by his captain, it is his duty to do everything in his power to dislodge
the batsman. It is really quite a secondary consideration for him whether
many or few runs are being made off his bowling.” As a sequel to this, he
urges that “a slow bowler should try every wile that can possibly be
attempted. By adopting slow bowling he has undertaken to use ‘the wisdom
of the serpent’ in the guise of the ‘harmlessness of the dove,’ and has
sacrificed pace to cunning and thought.”
If the bowler be very brave, he will feed the strong stroke of the
batsman. I often find this plan effective in Racquets and Tennis. The
opponent tries “just one too many,” or tries to excel beyond his ability. But
of course it would be a greater error to forget the fieldmen’s poor hands and
to bowl the batsman into practice and sure sight, than it would be to bowl
merely for maidens, unless the other bowler is playing ninepins with the
stumps, or unless defensive bowling is required at the close finish to a
match, or in order to excite a batsman to impatience.
Most experiments should have been already made at the nets or in
practice-games. It is there that you should learn how to lead up to a killing
ball, as the Lawn Tennis or Chess player does, rather than always to spring
the very best on the batsman at once. To plan each ball deliberately
beforehand, to let each have a definite purpose, involves not only these
previous trials, but also a good memory, an absence of hurry, a refusal to
despair.
Despair is almost natural when chances have been missed. I remember a
season of College Cricket during which I got about 130 wickets, and had
over 60 chances missed. I had to console myself by imagining each chance
—mostly to the sleepy slips—to be a wicket. That may console one slightly.
Another consolation is to remember that each fresh batsman is a fresh
beginning to the game. He comes in unready, a hope to the bowler.
Observation and memory have been invaluable helps to me at my own
games. I translate my experiences into Cricket language. From behind the
wicket and elsewhere, observe the commonest hits off the commonest balls
with this or that break, especially when the batsman shapes thus or thus.
Observe how the poking potterer is dismissed by the high full-pitch or by
the ball to entice a catch in the slips—for him you will note in your mind,
“Two short slips and perhaps two square legs.” Watch the fingers of the
nervous batsman grip the bat tight; watch the feet and body shuffle in
anxiety; watch the feeble strokes that result; watch the balls that worry him
most before he gets confidence.
The weak point of a batsman should be the point of most frequent attack,
and that weak point may differ on different days, and according to the
individual batsman’s special frame of mind. “Ah,” I have often thought
when I faced an old opponent, “if only I could tell your strongest and
weakest strokes to-day and now! Will you be slow on your legs now? Will
you neglect that right foot, oh, mine enemy?”
Observe whether the batsman himself is intelligent and observant, or—
what generally amounts to the same thing—practised to the verge of
automatism. Do not assume that every batsman will notice everything that
you are doing. Excessive wiliness is often wasted.
Observe how a player with a certain “stance” will tend to show a certain
fault—as to draw away his right foot. Classify players in groups. Then
when the hitherto new and “unseen” batsman arrives, you may start at an
advantage; you may save yourself unnecessary experimentation.
Make notes of these and other “tips.” Cricket is as well worth notes as
Tennis and Racquets, and my notes for these games have proved of yeoman
service in matches. “How they would give my whole show away!” was the
remark of an American player. “Yes,” I replied, “if anyone had the patience
to use them, he might very soon beat me.” Work out theories; remember the
keenness of Spofforth, who lay awake at nights plotting and planning. Such
imaginations are good for the intellect and (in an obvious way) “a very
present help in time of trouble.” Read, observe, ask pros., veterans, wicket-
keepers. Make notes, recollect, use. Judge by results.
For instance, work out where you will want this and that fielder placed.
Most books give excellent diagrams: Ranjitsinhji’s are the fullest. But do
not be tied down by any such diagram. Be ready to change the positions—
by a word or a movement of the hand—according to individual grounds,
days, batsmen, and so on.
One need not confine one’s practice to the nets and games. These are
indispensable in their place, but not self-sufficient. Practice with a smaller
and softer ball is not to be despised; it will give one freer movements, more
obvious effects in break, and thus more knowledge and confidence. And
one should do the special exercises—and others devised by wiser heads
than mine—before one dares to despair. One must first master the
mechanisms, try several actions, practise with a friend (putting a stump
between oneself and him, and bowling at it alternately with him, a third
enthusiast acting as wicket-keeper), practise needless variety (with wrist or
fingers stiff or loose, and so on). One can give oneself every chance, every
benefit of the doubt. It was years before I learnt to serve at Racquets or
Tennis. I am not nearly at my best yet.
When one is at the nets, one must be independent. One must imagine
oneself bowling in actual overs. One must notice where each ball, sent with
a special purpose, is generally hit. In my practice of Cricket I never did this;
in my practice of my own games I do it with marked results.
Boys should certainly practise, even if they do not regularly play, with a
smaller ball, a smaller bat, a shorter pitch. I wish that the M.C.C.
Committee would study the expressed opinions of Messrs. A. G. Steel,
Ranjitsinhji, Grace and others—elicit the hitherto unexpressed opinions of
other experts; discuss the matter, and then, if it seemed good, issue an
authoritative advice to schoolmasters and others, urging the use of adapted
ball, bat, and pitch. Though any one single measure would not suit all, yet it
would be convenient, and would be a step in the right direction. Let there be
light and small bats and balls.
It would be well also if old players would tell the young player to
practise lobs, to try the W. G. action round the wicket, to master the
mechanisms of ordinary overhand bowling, to avoid excessive pace, and
break; to practise at the nets as if he were bowling in an actual game, only
with more experimentation—to bowl an over, then have a rest; to make
notes; to work out theories; to be keen. A few words from a famous expert
come with a thousand times more force than any amount of advice from the
present writer, even though the latter be stating only most obvious and
incontrovertible truths. For the word of a successful man availeth much.
CHAPTER III.

FIELDING AND THROWING-IN.

The future of Cricket lies less perhaps with reform of the game itself than
with more adequate preparation for play, so that each part of each
department of it may be better done—done with more skill, more
enjoyment, more profit. And of all departments fielding needs most care
and favour. It must become so good and so interesting as to be a pride and a
pleasure, instead of—as it now is—a dulness and a drudgery.
The first requisite will be to realise that fielding is complex. Whereas
Cricket is often called a trinity of games, of which one member is fielding,
fielding itself, though regarded as a single occupation, involves a multitude
of arts and too often a multitude of sins. Quite apart from the different
qualities demanded for different places in the field, all fielders alike should
possess certain characteristics in common. In this chapter we shall speak of
fielding in general, referring the reader to the books by Ranjitsinhji and
others for special and exceptional information about special places. Thus
short slip may have to be ready not to move his feet but merely to shift his
weight, whereas cover must be ready to do both.
A few minutes’ study of the photographs of Hirst and Shrewsbury, and of
an actual or imaginary game, will show that as a rule many virtues are
needful. Ranjitsinhji gives the following nine Commandments:—
“There are certain rules which apply to all fieldsmen, viz.:—
1. Keep the legs together when the ball is hit straight to you and while
you are picking it up.
2. Always back up the man who is receiving the ball at the wicket, when
it is thrown in, but not too close.
3. Always try for a catch, however impossible it may seem.
4. Always be on the look-out and ready to start.
5. Run at top speed, but not rashly, the moment the ball is hit.
6. Use both hands whenever possible.
7. Do not get nervous if you make a mistake.
8. Obey your captain cheerfully and promptly.
9. Never be slack about taking up the exact position assigned to you;
never move about in an aimless, fidgetty manner.”
These Commandments apply to the whole side, since, as has been well
said, “In a true sense, the strength of a fielding side must be measured by its
weakest member, as that of a chain is measured by its weakest link. Then,
again, when there is a really bad fielder on a side, more balls seem to go to
him than to any one else. Put him where you will, he seems to attract the
ball.”
Let the reader fancy himself fielding at cover. What must be his habits?
He must be ready to back up the wicket-keeper.
He must be ready to start at once in any direction either with his legs or
with his arm or with both.
He must time the ball; he must also anticipate, his foreknowledge being
based on instinct, observation, and memory.
He may have to run and to run hard.
He may have to move his hands, or one of them, rapidly and accurately
towards the ball’s line of flight; this may involve a bending of trunk, and an
extension of limbs for stooping and stretching.
He must preserve or immediately recover balance.
He must be able to draw back his hands, or one of them, the instant that
the ball has touched them or it. This yielding movement must be timed to a
nicety.
He must grasp the ball either as a catch or as a ball to be thrown in.
In the latter case he must decide to which end, at what pace, etc., he will
throw it in.
He must then throw it in accurately. This last rule of fielding alone
postulates a special and difficult art.

Having found out what is to be practised, the would-be fielder must


realise that the practice as well as the fielding itself are abundantly worth
while. “That side would have been out for a third of the score if one or two
of us in our palmy days had been in the field,” remarked a veteran spectator
at a big match. This was quite true—catches were missed, and they were
costly enough. Ranjitsinhji says, “As to the importance of good fielding, it
is easy to prove it. Each catch that is missed simply adds another batsman to
the opposite side. If five catches are dropped, the side that drops them has
to all intents and purposes fifteen men to dispose of instead of ten.” Besides
the chances, there were the balls not anticipated, not stopped, not thrown in
smartly, not thrown in accurately. The so-called “safe” fielders often lost a
run by their safe waiting. “Patient waiting no loss” is a bad rule. Mr.
Edward Lyttelton laments this inferiority. What a contrast to Mr. V. K.
Royle, whose habit was to stand like a man ready to sprint in any direction,
even before the ball had been hit. Such a man either ran the batsman out or
else saved run after run by sheer terrorism; he did not slack off merely
because he thought the ball might possibly not come near him. He seemed
to be convinced that it certainly would come not necessarily to him but for
him to field. He was the ideal. And W. G. tells us of another: “My brother
Fred and Jupp used to go after everything and try for every catch, as if the
match depended on their individual efforts; and the extraordinary results
which followed surprised others as well as themselves. There is no finer
sight in the cricket field than a brilliant fieldsman doing his utmost; and
every feat that he performs meets with quick and hearty recognition by the
spectators.” Such examples and words make one feel that keenness and skill
and success are worth while. The alertness and rapidity with accuracy are
qualities for character and for life as well as for cricket.
After the complexity of fielding and its importance have been realised,
the next thing is to improve fielding. Why has it not been cultivated as a
piece of land that may become fruitful? Partly perhaps because the fielder is
not mentioned on the scoring-sheet (except for the catches, which go
chiefly to the bowler’s credit); partly because the long-sided practice-nets
render most fielding unnecessary; partly because fielders are not keen, and
that means because they do not field scientifically. Fielding is regarded as a
subsidiary and slavish drudgery, not as an important and fine art. And now
for a few possible remedies of a general character, to be supplemented by
others and by special training for special places in the field.
Every fielder should practise all-round fielding, while he makes one
particular place (or two) his speciality: the choice of this place should
depend on the mental as well as the physical qualities—on smart readiness,
power of extension, and so forth.
He should study the commonest hits to his place, learning the curves and
breaks which the ball will most frequently show.
He must be alert. Let me here quote Mr. Edward Lyttelton’s excellent
remarks:—“Unless strong measures are taken, the school-fieldsmen will
stand on their heels, while the ball is being hit; and this is generally the
cause of that heart-sickening want of life—that imperturbable middle-aged
decorum which is so often to be noticed among boy-cricketers of seventeen,
eighteen, nineteen years of age, and is enough, when seen, to make old
cricketers weep. But not to stand on the heels requires effort and stimulus;
and it is astonishing how often you may make the effort and reap no reward;
the ball doesn’t come. But when it does, what a change! The leap, the
determination that the batsman shall not score, the racing after the ball, are
all part of the same dash which must begin from the toes, not from the heel.
Now some of these early principles can be taught to a boy by taking him
singly, and throwing or hitting the ball, not too hard, either at him or to one
side just within his utmost reach; and, by constant encouragement and
exhortation, the trainer may induce him again and again to do violence to
his propriety, in the first place, and then to stretch his sinews and curve his
backbone till he finds himself capable of a brilliancy which he never before
suspected. The exercise is terrific, and ten minutes per diem are amply
sufficient. It is best to take only one at a time. No one can guess the
improvement that is sure to ensue if this régime is faithfully observed.... A
deep field is standing with his whole body ready to jump in any direction
that may be required. There comes a catch, but it is very doubtful if he can
get to it; only because he was ready to start he does so, and perhaps the best
bat on the side walks home; or, owing to the same fact, he again and again
saves a ball from going to the boundary. Now, if this is the case with a deep
field, how much more with cover-point and other ‘save one’ fields!”
He must notice and practice several waiting-positions, taking good
fielders as his models. Whichever he decides to use, he must not stand on
his heels. Fielders refuse to learn the art of readiness; so does our nation in
its daily life. It is the prompt readiness not to go in one direction only, but to
go in any direction, perhaps backwards, without loss of poise and self-
control—for the hands must be prepared to be extended anywhere, and at
the end of the extension to grasp securely. So far from such an alertness
being a common sight, an inalienable possession of most players, it is as
rare as open-mindedness. There is only one thing rarer in fielding, and this
is the custom of anticipating strokes, though heaven knows that similar
strokes have been repeated often enough to be observed and remembered!
But “education” does not encourage observation.
In addition to the readiness to get at the ball, there must be the readiness
to back up.
The fielder must follow each ball. If he finds this dull, let him pretend
that he is the fielder to whom the ball has been sent; let him field it in his
imagination.
In a bedroom or elsewhere he may practice stoopings and extensions (as
in Photograph XXVIII. of Hirst), a yielding of the hands and a rapidly
closed grip at the end of the extensions. All the common attitudes and
movements for stopping and receiving balls may be acquired outside the
field. The muscles must be familiarised with their future work; for, as Mr.
Lyttelton says, “If every field picked up and threw in as quickly as his knee
joints and the state of his arm allowed him, a very considerable percentage
of the runs usually scored would be saved.”
Catching may be learnt with a soft ball against a wall or in games of
catch. The hands should be held not too far apart nor too far from the body.
Both hands should be used, if possible. The difficulty is to judge the flight,
to time the instant to draw back just enough—for “he must learn to let the
ball come into his hands as into an Aunt Sally’s mouth. It is entirely wrong
to grab or snap at it”—and then to hold tight. There are brought into play
the senses of sight, of hearing—different sounds accompany different hits,
and in Racquets I get much help from what my ear tells me—and of touch,
as well as of other faculties.
As practice for stopping balls, wicket-keeping
XXVIII.—Fielding a low ball with one hand: the opposite leg is fully extended.
[To face page 112.

is good except for the feet. It teaches one to bend quickly, to extend
quickly; it cultivates pluck and patience and observation, since the wicket-
keeper must stand firm and wait and watch each ball if he hopes not to be
hurt.
Every cricketer—I would go so far as to say every ordinary human being
—should learn and practise throwing-in. Dr. Grace says that the player
“should practise picking-up and throwing-in underhand.” At first this
should be acquired as a separate accomplishment, till it can be incorporated
and nearly ingrafted into the action of fielding, so that the whole process
may become, as it were, a single movement started half-unconsciously by
the sight of a batsman preparing to strike. The right action for throwing will
be dealt with directly.
Interesting matches will do much to improve the keenness about fielding
and therefore the care given to it. It is mainly because the American School
and University baseball matches are so interesting, so absorbing, that good
fielding is so sedulously sought after. We might arouse and sustain interest
by variety; personally I should like to see handicap-matches occasionally
introduced. A few kinds are suggested in another chapter. Tip-and-run is
excellent training for the batsman as well for the fielders and wicket-keeper.
Subsidiary games and exercises are also essential. In these, as in
matches, there should either be prizes or—as Mr. Edward Lyttelton advises
—“the players should be encouraged to compete for colours to wear, which
need consist of nothing further than a cap of well-marked hue. There is no
reason to underrate the power of this enticement. Human beings have ever
been addicted to ornament, and some have thought that great wars have
been fought for very little else than the difference between one colour and
another. It is quite certain that the authorization of caps for proficiency in
cricket does wonders; and it is a stimulus quite innocent enough to be worth
trying.” The same writer goes on to suggest that “it ought to be possible to
devise a means of a social practice of fielding, which without involving the
waste of time of ordinary match fielding, would ensure to each individual
something to do, and some stimulus to do it.”
We might with advantage study American

XXIX.—Fielding, second position: the hand drawn back behind the ear somewhat
further back than most American Baseball fielders prefer.
[To face page 114.
methods of practice, not with a view to slavish copying, but with a view to
adapted borrowing. Mr. Walter Camp thus describes the method and
apparatus for improving the accuracy of height and of direction; after
remarking that “every one has what may be called a natural way of
throwing the ball, but this so-called natural ‘way’ usually means a perverted
method acquired through carelessness, or attempts to throw too hard before
the arm is sufficiently accustomed to the work,” he points out such faults as
to return the ball before the recovery of balance. He then goes on thus: “To
get an idea of the first steps towards the acquisition of this method, let the
player take the ball in his hand, and, bringing it back level with his ear,
planting both feet firmly, attempt to throw the ball without using the legs or
body. At first the throw is awkward and feeble, but constant practice
speedily results in moderate speed and peculiar accuracy. After steady
practice at this until quite a pace is acquired, the man may be allowed to use
his legs and body to increase the speed, still, however, sticking to the
straight-forward motion of the hand, wrist, and the arm.... There is no delay
caused by drawing back the arm past the head or by turning the body
around, which loses so much valuable time. Its accuracy is due to the fact
that it is easier to aim at an object with a hand in front of the eyes than
when it is out (to the side) beyond the shoulder. One can easily ascertain
this by comparing the ease of pointing the index finger at any object when
the hand is in front of the face, with the difficulty of doing so when the arm
is extended out sideways from the body. Still further, in the almost round-
arm throwing, which many players use, the hand describes an arc, and the
ball must be let go at the proper point to go true. If let go at any other point
in the swing, the throw is certain to be wild.... The majority of the best
throwers in the country use principally the fore-finger and middle finger in
giving direction to the ball.” Mr. Camp then describes the system of hitting
to a number of fielders—this is to be found in some English Schools, but in
America the practisers take it in turn to hit to the others, “the batter being
able to knock high flies, line hits, long flies, and occasionally a sharp hot
grounder; a good man, while avoiding running the men to death, will
XXX.—Waiting for a catch: elbows ready to draw back
slightly the moment the ball touches the hands.
[Between pages 116 and 117.
XXXI.—A one-handed catch: body bent slightly back from
the hips.
[Between pages 116 and 117.

occasionally give each man an opportunity to make a brilliant catch.


Nothing encourages and improves the candidates so much as keeping their
ambition thoroughly aroused during the entire time of practice.” “Exercise
that toughens the hands—such as swinging on the flying-rings, or rope-
climbing—is found to be useful.” “The work with the boxing gloves is
designed to improve the man’s general muscular development, make him
quick and firm upon his feet, and rapid in judgment and action.” “On the
running-track, the men take a few turns to limber up, and then practise
quick starting, and short, sharp spurts at full speed, rather than the more
leisurely, long-continued run of the men who are training for boating
honours.” “The sliding-spool is an admirable device for cultivating the
muscles used in throwing. (The spool is a piece of wood, like a large reel of
cotton, moving upon a rope tied, e.g., to a beam in a room, and to some
other object. It can be set at any angle.) The point at which the spool would
come in contact with the ceiling should be well padded with some rather
inelastic substance, in order that the spool may not rebound too severely. By
throwing the spool along the rope a number of times daily, a man can
acquire a powerful throw.”
From the above quotations it will be obvious that we have many lessons
to learn and adapt for ourselves from America, even while we need not
agree with all that is maintained here. Thus the action of the throw may be
better for certain individuals, certain places in the field, certain balls to be
fielded, when the hand is kept at about the level of the shoulder (see the
photograph of Hirst), or below that level. Murdoch, for instance, says,
“When throwing, get into the way of never allowing your arm to get above
the level of your shoulder: it must be a quick, wristy throw, and, with a little
practice, you will get very accurate.”
The captain should set a good example; he should also look out for keen
fielders or keen practisers of fielding and try to turn these into respectable
batsmen or bowlers, instead of starting with the latter and neglecting their
fielding qualifications.
Among the best exercises for fielding is Fives. It trains the left hand and
side, as well as the stooping-capacity. Boxing is another help, especially
quick-foot boxing (which my friend Mr. F. V. Hornby has
XXXII.—Fielding a ground ball; no interval left for the ball
to get through; body well down to the work.
[Between pages 118 and 119.
XXXIII.—A waiting position at point, where there is less foot-
work than at most places. It is easier to rise quickly than to
stoop quickly.
[Between pages 118 and 119.
XXXIV.—Preparing to throw in with the high action.
[Between pages 118 and 119.

described as “buzzing around”) rather than the stiff-legged methodical slow


kind. Boxing is fine for the “eye”—that is, for the co-operation of eye, foot,
body, arm, etc. Diving is good for the wind; swimming for this and other
purposes.
CHAPTER IV.

NOTES ON WICKET-KEEPING, CAPTAINING, IMPLEMENTS.

These subjects have been so thoughtfully dealt with in most of the well-
known books on Cricket, that it will be unnecessary here to do more than
sum up what seem to be the most useful points, and to add a few hints.

NOTES ON WICKET-KEEPING.
“The prevailing neglect of wicket-keeping is a gross folly. First as
regards those who are to be regular wicket-keepers, why do they never
practise? Their art is every whit as difficult as batting, and it is astonishing
how its supreme importance to the efficiency of an eleven is overlooked.
There is probably no hope of getting a really good man out on a good
wicket, which can be compared to the chance of his sending a catch to the
wicket-keeper before his eye is in. Sometimes these chances are missed,
and no one notices anything.... Every member of any team would gain if he
were taught how to keep wicket in early youth. In the first place it certainly
helps the eye in batting. The problem of judging pace, pitch, and break is
exactly the same in both cases. Next, it teaches sureness of hand in fielding.
A field who has learnt wicket-keeping must find any catch, especially if it
does not involve running, mere child’s play compared with a chance behind
the sticks. It is impossible that any such continuous exercise of hand and
eye of the most subtle description could be anything but valuable to the
general quickness and sureness both of fielding and batting. Lastly, even if
all the eleven do not learn to keep wicket, there ought always to be one or
more ready to take the place of the regular man, in case of injury or
absence.”—Edward Lyttelton.
In the plea for all-roundness we have already urged that every player
should be able to keep wicket a little, or at any rate should practise with the
ball and stump (see above). Wicket-keeping is useful not only for its own
sake and for the sake of the place which it may bring in the team, but also
as excellent discipline for short slip. The bowler himself must be able to
take the ball when it is thrown in by the fielders—and it is generally thrown
in remarkably badly—and to knock off the bails neatly and surely. The
captain, when he is not a bowler, sees more of the game—the strength or
weakness of the bowling and so on—if he is at the wicket than if he is at
point or elsewhere. As to fielding at mid-off, mid-on, and out in the country,
even for these places wicket-keeping encourages quick bending and
reaching, and general alertness of mind and unflagging attention—merits
which should be but seldom are insisted on in what we may call the
ordinary positions. The wicket-keeper must, in sheer self-defence, be quick
not merely to move but also to anticipate; he must be accurate to time the
ball and to use his wrist and fingers; he must adapt himself readily, as when
a ball is badly sent in by cover; he must observe the bowler and—half
unconsciously—the batsman; he must remember how this or that ball will
break, and so on; he must indeed know the whole game—all this, let us
repeat, if only in self-defence and to save trouble. In contrast to him, the
deep-fielder may go to sleep, or “stug” himself on his heels with legs stiff
and “thinking other things,” without appreciable interest in each and every
ball. The wicket-keeper dares not sleep: it would be as much as his face or
fingers are worth.
The habit of watching each ball carefully, of being ever ready
beforehand, is a habit that every batsman, every fielder and, we may add,
every watcher requires. A personal interest is attached habitually to
absolutely the whole performance and to each of the performers. The
wicket-keeper, whether he be captain or not, takes a more than fatherly
interest in every part of the play, for the sake of himself if not of his team.
Besides this, the almost compulsory pluck, since many balls, like nettles,
hurt less if taken boldly, the balance-shifting, the stooping and stretching
now here, now there, are certainly good for all play as well as for other
games, for physical development, and for health (especially as a preventive
for constipation). Anyone who studies the various positions (in photographs
or in actual play) of Mr. McGregor, of Storer, of any expert, will realise the
truth of this at once.
Nor is it possible, I think, even for a spectator to watch the game
satisfactorily unless he has sometimes stood himself behind the sticks and
seen the play from that point of view. The following hints may be of use to
those who wish to try wicket-keeping.
Every writer advises the wicket-keeper who has taken a ball on the leg-
side to put down the wicket on the chance of the batsman being out of his
ground. This is a good rule, though it is by no means easy to take a ball on
the leg-side, partly because the batsman himself obscures the view. This is
one reason why Hirst suggests that for fast bowling the not over-good
wicket-keeper should stand back unless the batsman often runs out.
To knock off the bails sharply on ordinary occasions is not so easy a
task. It is necessary to be able to take any ball neatly in spite of the break
and the bound. Hence it is good practice to get players to throw balls in to
the wicket from various parts of the field. Such practice helps both wicket-
keeper and fielders, but we never had it at school and of course at a college
no one takes any trouble about fielding. The wicket-keeper can tell the
fielder how and why his throwing is unsatisfactory, and can see that the
other fielders back up properly.
The wicket-keeper should be the adviser of the captain, pointing out to
him these details and also any useful changes of position. He may advise
the bowlers as well—but with discretion, lest he be confounded. Captains
and bowlers do not use their wicket-keeper nearly enough. He ought to be
an invaluable guide-book.
Dr. W. G. Grace describes the wicket-keeper’s position as follows:—
“Their hands are touching each other unless the ball is wide of the
wicket, and catching or stumping is done without any show or fuss. They
always stand with a full front to the bowler, and seldom move the feet
unless the ball is very wide.”
The wicket-keeper has to stretch in various directions with right or left
hand, now up, now down, now straight out. He needs the power of stooping
sideways. At the end of each extension, or at some intermediate place, he
must be able to draw back his hand or hands slightly so that they “give” to
the ball. If one studies the different places at which the ball is taken, one
can soon devise exercises to make the movements of the legs and trunk and
arms easier and quicker. The fast full movements are essential to success.
Boxing would be among the best of trainings for this as for most athletic
skill where large and—with many people—unwieldy limbs have to be
moved rapidly in any one of numerous ways according as the quick eye
shall telegraph to the obedient yet commanding brain.
NOTES ON CAPTAINING, ESPECIALLY AT SCHOOLS.
It often struck me, when I lectured to Civil Service candidates at
Cambridge, that to captain a Cricket or Football team well was an infinitely
better recommendation for a post than to know the dates of all the wars and
battles of the Romans. The former is a test of something more than
phonograph-accuracy. It is a test of leadership—of which virtue the
crammed smug who can only just scrape through the riding examination
may be quite devoid. But the art of captaincy counts nothing here: it only
counts in character and life.
Besides the power to command others, the ideal captain must have all-
round knowledge if he is to be able to find out where lie the strengths and
weaknesses of his team; he should have some practical and personal
acquaintance with all kinds of bowling and fielding as well as with wicket-
keeping and batting, so that he may give timely advice.
There is no need to carry the instructing of a team to an American
Football excess, but a hint from the land of exaggerations may be of use.
The Captain frequently consults every possible authority. Before an
important match—let us say between Harvard and Yale—old boys will
come down and talk over the team and the tactics and arrange special
“plays.” Every Captain should have a Committee which he may consult
when he is in doubt.
While he is choosing his team he should look among the juniors, as Mr.
Lyttelton advises. If he is a School-captain, he may notice two or three boys
keen on fielding and on practice generally (and, by the way, he himself
should set a good example here); perhaps these boys are trying the stump-
practice suggested in a previous chapter. Well, let him decide to turn these
boys into batsmen and bowlers as well, by urging them to whatever helps he
thinks good—perhaps to the practice with a bat along a line chalked on the
floor and to other exercises suggested here. Anyhow he must always be
looking out not only for promising young players, but also for keen young
fielders. The desire for batting or bowling may be taken for granted. It is the
fielders that are wanted. But of course the batting and bowling must be duly
considered. There should be at least one left-handed bowler. And there
should assuredly be an extra wicket-keep. Since the weather is so prominent
a factor in the game, and as some players are almost hopeless on a difficult
wicket, it might be suggested that the eleven for the most important matches
should have a wider margin for choice than is usual, though the possible
names must, for the sake of convenience, be decided on at least by the
previous day. So much for the choice of the team; and now for its practice.
As the team need not be decided on finally, till as late as possible, so
neither need be the positions of its members in the field, nor the order of
going in. The positions and the order should be occasionally changed.
The captain should insist on punctuality, on neatness of clothing, perhaps
even—if he dare—on clean hands as well as a pure heart, and certainly on
keenness. At school he should try to get the most distinguished old boys to
say a few words to the eleven.
He should also insist on all-roundness; he should insist that every
member occasionally keep wicket, and (as we have said above)
occasionally field in a place not his own, and occasionally bowl, and
occasionally bat under difficulties—as with a broom-stick at stump-cricket
or “snob.” Nothing more quickly reveals the crooked bat. The captain
himself should practise all these things, and especially fielding: otherwise
what right has he to curse? If he sees the interest flagging, he should
arrange more exciting matches. And he might do worse than devise some
system of handicaps.
When the members of a visiting eleven have arrived, the captain’s first
thought must be for them: he must put himself in their place. He may
delegate his duties to the second or third man in his team, so that he may
attend to the details of the ground and the play.
Before and during a home or “foreign” match he must set an example of
careful training and pure living, making it clear that excess is not manliness.
He must not be a prig: he need not say, “Don’t do that”; he can say, “I
shouldn’t do that if I were you.” He is not a schoolmaster, and, even if he
were, he might do worse than use that turn of phrase.
If he wins the toss, he should probably put his own side in. Many hold
this to be a rule without exception. Anyhow, he should inspect the ground
and notice any peculiarities of light, etc.
During the play he must be watchful of all sorts of things, and in the
field he should therefore be as near to the wicket as possible. Point is a
good place; wicket-keeping is still better, for then he can judge of the
bowling and give hints to the bowlers. If he himself be a bowler he should
have a candid friend who isn’t one; this candid friend must be consulted.
Other hints are given in abundance by the many well-known writers on
the game; to whose books we can safely refer the reader for such hints as
that the fast bowler should be put on against the tail of the enemy; that the
erratic bowler may be put on to break up a well-set pair.
These books the captain must read for himself. He must make notes from
them, unless he has a superlative memory. He must think. He must observe.
He must be tactful without weakness. Indeed, he should be far the most
intelligent man in the eleven; and, if he is, he is probably worth his place in
the eleven even if the utmost that he can do is to eat and drink in sensible
moderation, and watch and field with unflagging energy.

NOTES ON IMPLEMENTS.
One of the ablest of writers on Cricket, Mr. W. J. Ford, suggests “what
the cricket-bag should contain, apart from the actual weapons of offence
and defence.” He says: “It is a great addition to one’s comfort to have spare
socks and handkerchiefs (we may add vest and shirt) on board; a small
bandage is often useful, especially adhesive bandage. If you are lumbagic or
rheumatic, don’t omit a cholera belt of red flannel, and do not forget to put
it on when you come in steaming from a century, and have to sit in a
draughty pavilion. Sticking-plaster is often useful, so is a hair-brush,
likewise bags for boots; nothing is gained by mixing up muddy boots with
flannels, sweater, and blazer. Add a button-hook and shoe-horn.”
Boots are generally admitted to be preferable to shoes. They should be
easy, but not too easy. The American pattern of boot is among the best,
though anything more hideous than the black Lawn Tennis horror it would
be impossible to conceive. The boots must be white. A high authority says
that they need not have many nails, but too many nails are better than too
few, lest one trip or slip when one turns. It is common sense, as Shrewsbury
says, to put two near the toe, as runners do. Extra nails should be kept in the
cricket-bag, with the means for inserting them. A good nail is the
sparrowbill (from Shaw and Shrewsbury, Queen’s Square, Nottingham), or
the Nottingham nail.
Clothing in general, as Ranjitsinhji says, should satisfy the demands of
“ease, convenience, and comfort, as well as of health and cleanliness. The
shirt ought to be of canvas, wool, or flannel: flannel is always preferable if
the wearer can put up with the irritation. Both trousers and shirt should be
made to fit loosely, not flappingly. Boys are in the habit of putting on belts.
This is a mistake, since the noise the belt makes may at times be mistaken
for a catch at the wicket. I advise instead scarves or sashes, which also have
a smarter appearance.” So far as health is concerned, the flannel shirt
(which is worn by most professionals) renders the wearer less liable to chill
after a sweat, but hardens him far less than the linen shirt. Under either can
be worn a vest, after the habit of Shrewsbury and others, if the weather is at
all cold. The sash is not healthy, even though it is smarter than the belt—
which, by the way, need not be at all noisy.
Clean flannels should be used as often as possible, since to wear things
already rich in waste-products is not for the best. And flannels should never
be kept in closed apartments. At Columbia University, in America, the
lockers had wire trellis-work and not wooden covers, and the small
changing room for hundreds of men was quite free from disagreeable smell.
In case of severe heat a light sun-hat is safe.
In case of cold weather a sweater is usual. To field well with cold hands
is a miracle. At the beginning of the season thick kid gloves might be worn,
as they are by Abel and Shrewsbury; or at least they can be made to cover
those parts of the hand that blister most readily. Adhesive plaister round the
finger will save friction if a blister has already formed and burst or been
pricked.
The pads should be carefully chosen with a view to ease and lightness as
well as protection. Shrewsbury’s idea of an extra piece to protect the knee is
to be commended. Otherwise let the pads be only just thick and heavy
enough to give the feeling and the reality of safety. The fastenings should be
good and not of inferior leather or elastic.
Here as elsewhere this advice holds good, to choose your implements for
yourself; try before you buy; treat them with respect; learn how to mend
them; carry about the means of mending them. A “housewife” with needles,
good thread, scissors, safety pins, etc., will be invaluable. With a view to
care and cleanliness, keep your best bat in some sort of a cover.
As to the bat, for men and full-sized boys its weight might be 24½ to 25
oz., but that is less important than the ease with which the blade of the bat
rises. For a very slow wicket an extra 1½ to 2 oz. might be advisable, and
hence at least two bats may be taken in the bag, if only in case of change of
weather. But a comfortable feel is the great requisite, a comfortable feel not
merely as you stand and hold the bat but also as you move and use the bat.
If you have active feet and good shoulders and trunk then you may manage
a heavier bat than if you have less active feet and a weaker forearm and
wrist. The handle should bend lithely backwards and forwards rather than
sideways. It can be made thicker by wash-leather if the hands are moist; and
if they are wet, by the rubber covering, which adds over an ounce of weight
to the bat and thus helps the blade to rise. The wood of the bat is often
found to be cut away from all the bat except just the part with which one
hopes to stroke the ball. This, as Shrewsbury says, is not desirable, since
one cannot always judge the rise of the ball absolutely, and though a stroke
with the extra-fat part of the blade may be “very, very nice,” the stroke with
the thin part may be “horrid.” Shrewsbury’s bats are less exaggerated, so
that they allow the batsman more surface to drive well with.
The blade should be oiled say once a fortnight, but not too heavily, lest
the driving power be decreased. One needs a nice soft bat which after use
shall show not cracks but dents—a bat which shall have a slightly hollowed
middle-blade. In its infancy, use it with soft old balls by preference; train it
gently as a boxer might train his face to receive hard blows. Notice where
the dents come, and correct your play accordingly; those which are off the
best driving part are like the blue marks of the schoolmaster’s pencil. When
the bat is injured, use string-binding in preference to pegs; learn how to do
that string-binding, and keep a little string in your bag.
In your bag keep also a comfortable pair of batting-gloves and a ball.
“Neither a borrower nor a lender be”; certainly never lend a ball. I would
add also a Lawn Tennis ball and a stick; the latter if only in case of a walk
in new country, the former in case of a wet day when Snob-cricket is far
better than loafing. Every pavilion should allow of this game, as every ship
should allow of deck Cricket. The game should be played with a soft ball
and stick or stump, not with a hard ball and bat.
If you take a favourite book also, a Membook or Diary with a pencil, and
also a complete list of all the things you want in the bag, so that you never
have to borrow what may not fit you, or be as the foolish virgins, you will
be better off than nine out of ten cricketers are.
CHAPTER V.

THE IMPORTANCE OF ALL-ROUNDNESS IN CRICKET.

“The right and proper thing would be for cricketers to pay equal attention to
bowling, batting, and fielding, especially in their young days. All are
equally essential parts of the game. Why not regard them as equally
valuable? The doctrine of the division of labour holds good in cricket as
elsewhere, but every cricketer should, as far as lies in him, qualify himself
for every emergency. Most amateurs take no trouble whatever with their
bowling, except in matches.”—Ranjitsinhji.
I have heard it said that Richter, the great conductor, could himself play
every instrument used in his own orchestra, so that at once he knew where
and how the general effect was weak. On the same principle the captain of a
team should as a rule be an all-round player—a batsman, bowler, fielder,
watcher—though there are some captains who do not excel much in any
sphere except captaining, and yet are worth their place in their team.
But it is not merely the captain who gains by being an all-round player.
Cricket has as its object to fit every cricketer for his all-round life, as games
and exercises prepare young animals for their narrower life. We have used
games with this result if not with this object for generations past; year by
year, whether we know it or not, we shall have to rely on them more and
more. And anyhow a certain time, perhaps amounting to hundreds of hours,
is sure to be given to the play. Therefore it is as well to get the most that we
can out of that time, and to get the most that we can out of each department
of Cricket; in the spirit of Shrewsbury, studying it as a pleasant art; with
Abel, entering into it keenly and smartly; and, like Hirst, aiming at many-
sided excellence.
We cannot all be Hirsts, F. S. Jacksons, J. R. Masons, T. Haywards, A. G.
Steels, and so on; that is obvious. But most players are content never to try,
or else to try wrongly and then give up. There never was a greater error.
Let us consider batting alone. Even for successful and therefore
enjoyable batting (batting has been, is, and will be most enjoyed and most
sought after, and therefore has been, is, and will be least uncultivated; many
cultivate nothing besides), even for this we need more than practice at a net
or in a game, indispensable as these are in their proper place.
First of all, unless we are genius-players, we need a knowledge of
bowling; we need not only to see the bowler’s wrist and fingers, but also to
get an idea of what will happen to the ball when it has left the fingers. In
Tennis I never knew what was going to happen to a service until I learnt
how to serve. Otherwise I played as if there would be no special cut or twist
or drag. So practice in bowling may give the best knowledge of bowling for
the batsman’s purpose. Take a Lawn Tennis ball, and study the ways of
producing various breaks, etc.—I recommend a Lawn Tennis ball because it
shows the break more clearly, and can be used in a room; then produce
these breaks with a Cricket ball (don’t let it loose) before a large mirror.
After a time you will know what to expect when you see certain signs, such
as the middle and third finger curled inwards against the bowler’s palm.
Besides, when you have yourself bowled certain balls, you will know where
the batsman generally hits them, and what faults he generally makes. You
can avoid these faults, while on the other hand you can see at once, when
you go in, where the fielding offers a gap. It is not every bowler who knows
his own weak spots.
As a wicket-keeper one might learn still more about batting than one
could as a bowler. It is amazing to me that so few wicket-keepers can bat
even with moderate success. They seem to degenerate, like the idle
watchers, with too much watching and too much “knowledge!” The wicket-
keeper sees most of the game, and especially the batsman’s faults and the
bowler’s merits of break, spin, change of pace, and so on. He has to watch
the bowler’s wrist and fingers. He should know precisely what balls should
be left alone.
Only a few degrees less useful for batting is a knowledge of fielding in
all parts of the field, though every fielder should have one or two
specialities. The good fielder, when he bats, can remember the curl of the
ball hit to third man; he can observe cover-point’s attitude of slackness and
steal an easy run, for he knows that a sloucher cannot run him out.
And to watch a game well—that may be as valuable a help for batting as
bowling, wicket-keeping, or fielding. Shrewsbury will observe the play and
its many niceties—the duel between a good bowler and a good batsman—
from various parts of the field as he walks about; he will study length, pace,
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like