R software
Patrick Burns1 30th April 2011
1 This document resides in the tutorial section of http://www.burns-stat.com. More elementary material on R may also be found there. S+ is a registered trademark of TIBCO Software Inc. The author thanks D. Alighieri for useful comments.
Contents
Contents List of Figures List of Tables 1 Falling into the Floating Point Trap 2 Growing Objects 1 6 7 9 12
3 Failing to Vectorize 17 3.1 Subscripting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 3.2 Vectorized if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.3 Vectorization impossible . . . . . . . . . . . . . . . . . . . . . . . 22 4 Over-Vectorizing 5 Not 5.1 5.2 5.3 24
Writing Functions 27 Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Simplicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Consistency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 35 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 38 39 39 40 40 40 41 42 42
6 Doing Global Assignments 7 Tripping on Object Orientation 7.1 S3 methods . . . . . . . . . . . 7.1.1 generic functions . . . . 7.1.2 methods . . . . . . . . . 7.1.3 inheritance . . . . . . . 7.2 S4 methods . . . . . . . . . . . 7.2.1 multiple dispatch . . . . 7.2.2 S4 structure . . . . . . . 7.2.3 discussion . . . . . . . . 7.3 Namespaces . . . . . . . . . . .
1
CONTENTS 8 Believing It Does as Intended 8.1 Ghosts . . . . . . . . . . . . . . . . . . . . . . 8.1.1 differences with S+ . . . . . . . . . . . 8.1.2 package functionality . . . . . . . . . . 8.1.3 precedence . . . . . . . . . . . . . . . 8.1.4 equality of missing values . . . . .