Advanced R 1st Edition Hadley Wickham Download
Advanced R 1st Edition Hadley Wickham Download
https://ebookultra.com/download/advanced-r-1st-edition-hadley-
wickham/
https://ebookultra.com/download/the-master-bedroom-tessa-hadley/
https://ebookultra.com/download/advanced-onsite-wastewater-systems-
technologies-1st-edition-anish-r-jantrania/
https://ebookultra.com/download/handbook-for-waterworks-operator-
certification-advanced-level-volume-iii-1st-edition-frank-r-spellman/
https://ebookultra.com/download/sleepwalking-into-a-new-world-the-
emergence-of-italian-city-communes-in-the-twelfth-century-chris-
wickham/
https://ebookultra.com/download/spellman-s-standard-handbook-for-
wastewater-operators-volume-iii-advanced-level-second-edition-frank-r-
spellman/
https://ebookultra.com/download/the-comprehensive-respiratory-
therapist-exam-review-entry-and-advanced-levels-5e-5th-edition-james-
r-sills/
Advanced R
topic and is well known and appreciated throughout the entire R
community. This is the great strength of the book and the primary
reason it deserves to be published. It addresses a topic where there
Advanced R
is already a growing number of books, but few have the depth, the
technical accuracy, and the authority of this one.”
—Bill Venables, CSIRO
Advanced R presents useful tools and techniques for attacking
many types of R programming problems, helping you avoid mis-
takes and dead ends. With more than ten years of experience pro-
gramming in R, the author illustrates the elegance, beauty, and flex-
ibility at the heart of R.
The book develops the necessary skills to produce quality code that
can be used in a variety of circumstances. You will learn:
• The fundamentals of R, including standard data types and
functions
• Functional programming as a useful framework for solving wide
classes of problems
• The positives and negatives of metaprogramming
• How to write fast, memory-efficient code
This book not only helps current R users become R programmers
but also shows existing programmers what’s special about R. Inter-
mediate R programmers can dive deeper into R and learn new strat-
egies for solving diverse problems while programmers from other Wickham
languages can learn the details of R and understand why R works
the way it does.
Hadley Wickham
K20319
w w w. c rc p r e s s . c o m
Series Editors
John M. Chambers Torsten Hothorn
Department of Statistics Division of Biostatistics
Stanford University University of Zurich
Stanford, California, USA Switzerland
Customer and Business Analytics: Applied Data Mining for Business Decision
Making Using R, Daniel S. Putler and Robert E. Krider
Hadley Wickham
This book contains information obtained from authentic and highly regarded sources. Reasonable
efforts have been made to publish reliable data and information, but the author and publisher cannot
assume responsibility for the validity of all materials or the consequences of their use. The authors and
publishers have attempted to trace the copyright holders of all material reproduced in this publication
and apologize to copyright holders if permission to publish in this form has not been obtained. If any
copyright material has not been acknowledged please write and let us know so we may rectify in any
future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced,
transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or
hereafter invented, including photocopying, microfilming, and recording, or in any information stor-
age or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access www.copy-
right.com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222
Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that pro-
vides licenses and registration for a variety of users. For organizations that have been granted a photo-
copy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are
used only for identification and explanation without intent to infringe.
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
To Jeff, who makes me happy, and who made
sure I had a life outside this book.
Contents
1 Introduction 1
1.1 Who should read this book . . . . . . . . . . . . . . . . 3
1.2 What you will get out of this book . . . . . . . . . . . . 3
1.3 Meta-techniques . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Recommended reading . . . . . . . . . . . . . . . . . . 5
1.5 Getting help . . . . . . . . . . . . . . . . . . . . . . . . 6
1.6 Acknowledgments . . . . . . . . . . . . . . . . . . . . . 6
1.7 Conventions . . . . . . . . . . . . . . . . . . . . . . . . 8
1.8 Colophon . . . . . . . . . . . . . . . . . . . . . . . . . . 8
I Foundations 11
2 Data structures 13
2.1 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.1.1 Atomic vectors . . . . . . . . . . . . . . . . . . . 15
2.1.1.1 Types and tests . . . . . . . . . . . . . 16
2.1.1.2 Coercion . . . . . . . . . . . . . . . . . 16
2.1.2 Lists . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1.3 Exercises . . . . . . . . . . . . . . . . . . . . . . 19
2.2 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.2.0.1 Names . . . . . . . . . . . . . . . . . . 20
2.2.1 Factors . . . . . . . . . . . . . . . . . . . . . . . 21
2.2.2 Exercises . . . . . . . . . . . . . . . . . . . . . . 23
2.3 Matrices and arrays . . . . . . . . . . . . . . . . . . . . 24
ix
x Contents
2.3.1 Exercises . . . . . . . . . . . . . . . . . . . . . . 26
2.4 Data frames . . . . . . . . . . . . . . . . . . . . . . . . 27
2.4.1 Creation . . . . . . . . . . . . . . . . . . . . . . . 27
2.4.2 Testing and coercion . . . . . . . . . . . . . . . . 28
2.4.3 Combining data frames . . . . . . . . . . . . . . 28
2.4.4 Special columns . . . . . . . . . . . . . . . . . . . 29
2.4.5 Exercises . . . . . . . . . . . . . . . . . . . . . . 30
2.5 Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3 Subsetting 33
3.1 Data types . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.1.1 Atomic vectors . . . . . . . . . . . . . . . . . . . 34
3.1.2 Lists . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.1.3 Matrices and arrays . . . . . . . . . . . . . . . . 37
3.1.4 Data frames . . . . . . . . . . . . . . . . . . . . . 38
3.1.5 S3 objects . . . . . . . . . . . . . . . . . . . . . . 39
3.1.6 S4 objects . . . . . . . . . . . . . . . . . . . . . . 39
3.1.7 Exercises . . . . . . . . . . . . . . . . . . . . . . 39
3.2 Subsetting operators . . . . . . . . . . . . . . . . . . . . 40
3.2.1 Simplifying vs. preserving subsetting . . . . . . . 41
3.2.2 $ . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.2.3 Missing/out of bounds indices . . . . . . . . . . . 44
3.2.4 Exercises . . . . . . . . . . . . . . . . . . . . . . 45
3.3 Subsetting and assignment . . . . . . . . . . . . . . . . 45
3.4 Applications . . . . . . . . . . . . . . . . . . . . . . . . 46
3.4.1 Lookup tables (character subsetting) . . . . . . . 46
3.4.2 Matching and merging by hand (integer subset-
ting) . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.4.3 Random samples/bootstrap (integer subsetting) 48
3.4.4 Ordering (integer subsetting) . . . . . . . . . . . 49
Contents xi
4 Vocabulary 57
4.1 The basics . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.2 Common data structures . . . . . . . . . . . . . . . . . 59
4.3 Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . 60
4.4 Working with R . . . . . . . . . . . . . . . . . . . . . . 61
4.5 I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
5 Style guide 63
5.1 Notation and naming . . . . . . . . . . . . . . . . . . . 63
5.1.1 File names . . . . . . . . . . . . . . . . . . . . . 63
5.1.2 Object names . . . . . . . . . . . . . . . . . . . . 64
5.2 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.2.1 Spacing . . . . . . . . . . . . . . . . . . . . . . . 65
5.2.2 Curly braces . . . . . . . . . . . . . . . . . . . . 66
5.2.3 Line length . . . . . . . . . . . . . . . . . . . . . 67
5.2.4 Indentation . . . . . . . . . . . . . . . . . . . . . 67
5.2.5 Assignment . . . . . . . . . . . . . . . . . . . . . 67
5.3 Organisation . . . . . . . . . . . . . . . . . . . . . . . . 68
5.3.1 Commenting guidelines . . . . . . . . . . . . . . 68
xii Contents
6 Functions 69
6.1 Function components . . . . . . . . . . . . . . . . . . . 71
6.1.1 Primitive functions . . . . . . . . . . . . . . . . . 71
6.1.2 Exercises . . . . . . . . . . . . . . . . . . . . . . 72
6.2 Lexical scoping . . . . . . . . . . . . . . . . . . . . . . . 73
6.2.1 Name masking . . . . . . . . . . . . . . . . . . . 74
6.2.2 Functions vs. variables . . . . . . . . . . . . . . . 75
6.2.3 A fresh start . . . . . . . . . . . . . . . . . . . . 76
6.2.4 Dynamic lookup . . . . . . . . . . . . . . . . . . 77
6.2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . 78
6.3 Every operation is a function call . . . . . . . . . . . . 79
6.4 Function arguments . . . . . . . . . . . . . . . . . . . . 81
6.4.1 Calling functions . . . . . . . . . . . . . . . . . . 81
6.4.2 Calling a function given a list of arguments . . . 83
6.4.3 Default and missing arguments . . . . . . . . . . 83
6.4.4 Lazy evaluation . . . . . . . . . . . . . . . . . . . 84
6.4.5 ... . . . . . . . . . . . . . . . . . . . . . . . . . . 88
6.4.6 Exercises . . . . . . . . . . . . . . . . . . . . . . 89
6.5 Special calls . . . . . . . . . . . . . . . . . . . . . . . . 89
6.5.1 Infix functions . . . . . . . . . . . . . . . . . . . 90
6.5.2 Replacement functions . . . . . . . . . . . . . . . 91
6.5.3 Exercises . . . . . . . . . . . . . . . . . . . . . . 93
6.6 Return values . . . . . . . . . . . . . . . . . . . . . . . 94
6.6.1 On exit . . . . . . . . . . . . . . . . . . . . . . . 97
6.6.2 Exercises . . . . . . . . . . . . . . . . . . . . . . 97
6.7 Quiz answers . . . . . . . . . . . . . . . . . . . . . . . . 98
Contents xiii
7 OO field guide 99
7.1 Base types . . . . . . . . . . . . . . . . . . . . . . . . . 101
7.2 S3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
7.2.1 Recognising objects, generic functions, and meth-
ods . . . . . . . . . . . . . . . . . . . . . . . . . . 102
7.2.2 Defining classes and creating objects . . . . . . . 105
7.2.3 Creating new methods and generics . . . . . . . 106
7.2.4 Method dispatch . . . . . . . . . . . . . . . . . . 107
7.2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . 109
7.3 S4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.3.1 Recognising objects, generic functions, and meth-
ods . . . . . . . . . . . . . . . . . . . . . . . . . . 111
7.3.2 Defining classes and creating objects . . . . . . . 113
7.3.3 Creating new methods and generics . . . . . . . 115
7.3.4 Method dispatch . . . . . . . . . . . . . . . . . . 115
7.3.5 Exercises . . . . . . . . . . . . . . . . . . . . . . 116
7.4 RC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
7.4.1 Defining classes and creating objects . . . . . . . 117
7.4.2 Recognising objects and methods . . . . . . . . . 119
7.4.3 Method dispatch . . . . . . . . . . . . . . . . . . 119
7.4.4 Exercises . . . . . . . . . . . . . . . . . . . . . . 120
7.5 Picking a system . . . . . . . . . . . . . . . . . . . . . . 120
7.6 Quiz answers . . . . . . . . . . . . . . . . . . . . . . . . 121
8 Environments 123
8.1 Environment basics . . . . . . . . . . . . . . . . . . . . 124
8.1.1 Exercises . . . . . . . . . . . . . . . . . . . . . . 130
8.2 Recursing over environments . . . . . . . . . . . . . . . 130
8.2.1 Exercises . . . . . . . . . . . . . . . . . . . . . . 132
8.3 Function environments . . . . . . . . . . . . . . . . . . 133
Random documents with unrelated
content Scribd suggests to you:
T227. Topper Makes a Movie, by Philip Rapp. © 18Mar55;
LP5070.
T228. Topper Fights a Duel, by Philip Rapp. © 8Apr55; LP5062.
T229. Topper’s Egyptian Deal, by Robert Riley Crutcher. ©
15Apr55; LP5063.
T230. King Cosmo the First, by Philip Rapp. © 25Mar55;
LP5060.
T231. Topper’s Highland Fling, by Robert Riley Crutcher. ©
20May55; LP5065.
T232. Topper Goes to School, by Philip Rapp. © 6May55;
LP5068.
T233. Topper’s Insurance Scandal, by Philip Rapp. © 17Jun55;
LP5225.
T234. The Blood Brother, by Stanley Davis and Elon Packard. ©
13May55; LP5069.
T235. Topper’s Desert Island, by Robert Riley Crutcher. ©
27May55; LP5066.
T236. Topper’s Vacation, by Robert Riley Crutcher. © 1Jul55;
LP5227.
T237. Topper’s Other Job, by Philip Rapp. © 24Jun55; LP5226.
T238. Topper’s Uranium Pile, by Don Mullally. © 22Apr55;
LP5064.
T239. Topper’s Counterfeiters, by Robert Riley Crutcher. ©
10Jun55; LP5143.
Peter Gunn.
26 Men.
Fury.
Tales of the Texas Rangers, no. 11.
Trailer.
1. Sea Saboteurs.
2. Death Takes the Deck.
3. Five Fathoms Down.
4. On Target!
5. The Fire Ship.
6. Collision.
7. War in the Hills.
8. Native Execution.
9. Mass Attack.
10. Machine Murder.
11. Underwater Ambush.
12. Twisted Vengeance.
Navy Log.
You’ll Never Get Rich.
The Honeymooners.
Lassie.
The Lone Ranger.
Sergeant Preston of the Yukon.
Lassie.
Meet Mr. McNutley.
TREE-CORNERED TWEETY. Warner Bros. Cartoons. 7 min., sd.,
color, 35mm. (Merrie Melodies Cartoon) Technicolor. ©
Vitaphone Corp.; 19May56 (in notice: 1955); MP8190.
A TREE FOR PLANTING. SEE The Texan, no. 14.
TREE FOR TWO. Warner Bros. Cartoons, 1952. 7 min., sd., color,
35mm. (Merrie Melodies Cartoon) © The Vitaphone Corp.;
6Nov52 (in notice: 1951); MP2940.
THE TREE HOUSE. SEE Lassie.
THE TREE MEDIC. Universal Pictures Co. 6 min., sd., color,
35mm. (Walter Lantz Woody Woodpecker Cartune) A Universal
International picture. Technicolor. © Universal International;
9Dec55; LP5679.
TREE OF DEATH. SEE Buckskin.
TREE PORTRAITS. State University of New York, College of
Forestry. 21 min., sd., color, 16mm. © State University of New
York, College of Forestry; 10May55; MP6749.
TREE TO TRADE. Long-Bell Lumber Co., 1950. 33 min., sd., color,
16mm. © The Long-Bell Lumber Co.; 28Dec50; MP943.
TREE’S A CROWD. Universal International. 1 reel, sd.,
Technicolor, 35mm. (Walter Lantz Woody Woodpecker Cartune)
© Universal International; 25Aug58; LP12523.
TREES AND JAMAICA DADDY. UPA Pictures. Released by
Columbia Pictures Corp. 1 reel, sd., Technicolor, 35mm. (Ham
and Hattie) © Columbia Pictures Corp.; 30Jan58 (in notice:
1957); LP9900.
TREES: HOW WE IDENTIFY THEM. Coronet Instructional Films.
11 min., sd., b&w, 16mm. © Coronet Instructional Films, a
division of Esquire, Inc.; 2Jun58; MP9270.
TRENT’S LAST CASE. Imperadio Pictures, London. Released in
the U. S. by Republic Pictures Corp. 90 min., sd., b&w, 35mm.
Based on the book of the same title by E. C. Bentley. © Republic
Pictures Corp.; 29Oct52; LP3108.
LOS TRES ALEGRES COMPADRES. (The Three Merry Partners)
Producciones Mier y Brooks, Mexico. Released by Clasa-Mohme;
in the U. S. by Importadora. 118 min., sd., b&w, 35mm. Appl.
author: Productora Mier y Brooks, S. de R. L. y C. V. ©
Importadora, Inc.; 15Apr52; LP10637.
TRES BRIBONES. (Three Scoundrels) Cinematografica Jalisco,
Mexico. Released in the U. S. by Importadora. 88 min., sd., b&w,
35mm. © Importadora, Inc.; 15Mar55; LP10869.
TRES HOMBRES EN MI VIDA. (Three Men in My Life) Filmadora
Internacional, Mexico. Released by Clasa-Mohme; in the U. S. by
Importadora. 91 min., sd., b&w, 35mm. © Importadora, Inc.;
1May52; LP11842.
THE TRESTLE. SEE Your All Star Theatre.
TRIAL. Metro-Goldwyn-Mayer. Released by Loew’s. 109 min., sd.,
b&w, 35mm. Based on the novel by Don M. Mankiewicz. ©
Loew’s Incorporated; 15Aug55; LP5314.
THE TRIAL. SEE
A TRIP AROUND THE BLOCK. SEE All Star Theatre, no. 83.
A TRIP THRU ADVENTURELAND. SEE Disneyland. 1955-1956,
no. 25.
A TRIP TO AUNT SARAH’S. SEE The Whistler, no. 11.
A TRIP TO HILLSBOROUGH. SEE Father Knows Best, no. 87.
TRIP TO LISBON. SEE Topper, no. T122.
A TRIP TO TAHITI. SEE The George Burns and Gracie Allen
Show, no. 242.
A TRIP TO THE MOON. Encyclopaedia Britannica Films. 16 min.,
sd., color, 16mm. © Encyclopaedia Britannica Films, Inc.;
19Dec57; MP8932.
A TRIP TO THE UNITED STATES MILITARY ACADEMY, WEST
POINT, NEW YORK. SEE Let’s Take a Trip, May 5, 1957.
TRIP TO WISCONSIN. SEE Make Room for Daddy, no. 30A.
TRIPLE CROSS. SEE Lone Ranger Series, no. 115.
TRIPLE CROSSED. Columbia Pictures Corp. 2 reels, sd., b&w,
35mm. (The Three Stooges) © Columbia Pictures Corp.; 2Feb59
(in notice: 1958); LP12882.
TRIPLE EXPOSURE. SEE Sky King, no. 39.
TRIPLE JEOPARDY. Lindsley Parsons Productions, 1952. 25 min.,
sd., b&w, 16mm. (Crime File Series, no. 8) © Lindsley Parsons
Productions, Inc.; 4Mar52; LP1521.
THE TRIPLE SURPRISE PARTY. SEE The George Burns and
Gracie Allen Show, no. 194.
TRIPLE THREAT STARS. Chevrolet Motor Division, General
Motors Corp. [1952] Produced by Jam Handy Organization. 69
ft., b&w, 35mm. © The Jam Handy Organization, Inc.; 18Apr52;
MU5410.
TRIPLE TROUBLE. Monogram Pictures Corp., 1950. 66 min., sd.,
b&w, 35mm. © Monogram Pictures Corp.; 13Aug50; LP269.
TRIPLET TROUBLE. Loew’s, 1952. 7 min., sd., color, 35mm. (Tom
and Jerry Cartoon) A Metro-Goldwyn-Mayer cartoon. © Loew’s
Incorporated; 31Jan52; LP1468.
TRIPOLI. Paramount Pictures Corp., 1950. 95 min., sd., color,
35mm. © Paramount Pictures Corp.; 1Nov50; LP468.
TRIPTYCH. Halprin-Lathrop Foundation. 10 min., sd., color,
16mm. Kodachrome. Adapted from the dance Three Characters
for a Passion Play, composed and performed by Welland
Lathrop. © Welland Lathrop & J. Padgett Payne; 1Nov55;
MP6754.
TRIUMPH AND DEFEAT. Cathedral Films. 30 min., sd., b&w,
16mm. (The Living Christ Series, no. 11) With teacher’s study
guide. Screenplay, Arthur T. Horman. © JKF Productions;
1Feb57; MP8046.
THE TRIUMPH OF ALEXANDER THE GREAT. SEE You Are
There.
THE TRIUMPH OF LOUIS BRAILLE. SEE You Are There.
TRIUMPHANT. Broadman Films. 17 min., sd., color, 16mm. (BFS,
117) Eastman color. Appl. author: Earl Waldrup. © Broadman
Films; 1Jul57; MP8351.
THE TRIUMPHANT. SEE Lilli Palmer Presents the Quality
Theatre.
LES TROIS MESSES BASSES. SEE Les Lettres de Mon Moulin.
LES TROIS MOUSQUETAIRES. SEE Lady in the Iron Mask.
TROMBA THE TIGER MAN. Camera Filmproduktion, Hamburg.
Released in the U. S. by Lippert Pictures, 1952. 61 min., sd., b&w,
35mm. English dialogue dubbed in. © Camerafilm Productions;
6Nov52 (in notice: 1947); LP2038.
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.
ebookultra.com