Contents
1 Introducing R 1
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 A note on the text . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 R Language Fundamentals 5
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.1 A brief introduction to R . . . . . . . . . . . . . . . . 5
2.1.2 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.1.3 A very brief introduction to OOP in R . . . . . . . . . 7
2.1.4 Some special values . . . . . . . . . . . . . . . . . . . 8
2.1.5 Types of objects . . . . . . . . . . . . . . . . . . . . . 9
2.1.6 Sequence generating and vector subsetting . . . . . . . 11
2.1.7 Types of functions . . . . . . . . . . . . . . . . . . . . 12
2.2 Data structures . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.1 Atomic vectors . . . . . . . . . . . . . . . . . . . . . . 12
2.2.2 Numerical computing . . . . . . . . . . . . . . . . . . 15
2.2.3 Factors . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2.4 Lists, environments and data frames . . . . . . . . . . 18
2.3 Managing your R session . . . . . . . . . . . . . . . . . . . . . 22
2.3.1 Finding out more about an object . . . . . . . . . . . 24
2.4 Language basics . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.4.1 Op erators . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.5 Subscripting and subsetting . . . . . . . . . . . . . . . . . . . 28
2.5.1 Vector and matrix subsetting . . . . . . . . . . . . . . 29
2.6 Vectorized computations . . . . . . . . . . . . . . . . . . . . . 36
2.6.1 The recycling rule . . . . . . . . . . . . . . . . . . . . 37
2.7 Replacement functions . . . . . . . . . . . . . . . . . . . . . . 38
2.8 Functional programming . . . . . . . . . . . . . . . . . . . . . 39
2.9 Writing functions . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.10 Flow control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.10.1 Conditionals . . . . . . . . . . . . . . . . . . . . . . . 44
2.11 Exception handling . . . . . . . . . . . . . . . . . . . . . . . . 45
2.12 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.12.1 Standard evaluation . . . . . . . . . . . . . . . . . . . 51
2.12.2 Non-standard evaluation . . . . . . . . . . . . . . . . . 52
vii

Get R Programming for Bioinformatics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.