logo资料库

R语言核心技术手册 英文版 R in a nutshell.pdf

第1页 / 共636页
第2页 / 共636页
第3页 / 共636页
第4页 / 共636页
第5页 / 共636页
第6页 / 共636页
第7页 / 共636页
第8页 / 共636页
资料共636页,剩余部分请下载后查看
Table of Contents
Preface
Why I Wrote This Book
When Should You Use R?
R License Terms
Examples
How This Book Is Organized
Conventions Used in This Book
Using Code Examples
How to Contact Us
Safari® Books Online
Acknowledgments
Part I. R Basics
Chapter 1. Getting and Installing R
R Versions
Getting and Installing Interactive R Binaries
Windows
Mac OS X
Linux and Unix Systems
Installation using package management systems
Installing R from downloaded files
Chapter 2. The R User Interface
The R Graphical User Interface
Windows
Mac OS X
Linux and Unix
The R Console
Command-Line Editing
Batch Mode
Using R Inside Microsoft Excel
Other Ways to Run R
Chapter 3. A Short R Tutorial
Basic Operations in R
Functions
Variables
Introduction to Data Structures
Objects and Classes
Models and Formulas
Charts and Graphics
Getting Help
Chapter 4. R Packages
An Overview of Packages
Listing Packages in Local Libraries
Loading Packages
Loading Packages on Windows and Linux
Loading Packages on Mac OS X
Exploring Package Repositories
Exploring Packages on the Web
Finding and Installing Packages Inside R
Windows and Linux GUIs
Mac OS X GUI
R console
Installing from the command line
Custom Packages
Creating a Package Directory
Building the Package
Part II. The R Language
Chapter 5. An Overview of the R Language
Expressions
Objects
Symbols
Functions
Objects Are Copied in Assignment Statements
Everything in R Is an Object
Special Values
NA
Inf and -Inf
NaN
NULL
Coercion
The R Interpreter
Seeing How R Works
Chapter 6. R Syntax
Constants
Numeric Vectors
Character Vectors
Symbols
Operators
Order of Operations
Assignments
Expressions
Separating Expressions
Parentheses
Curly Braces
Control Structures
Conditional Statements
Loops
Accessing Data Structures
Data Structure Operators
Indexing by Integer Vector
Indexing by Logical Vector
Indexing by Name
R Code Style Standards
Chapter 7. R Objects
Primitive Object Types
Vectors
Lists
Other Objects
Matrices
Arrays
Factors
Data Frames
Formulas
Time Series
Shingles
Dates and Times
Connections
Attributes
Class
Chapter 8. Symbols and Environments
Symbols
Working with Environments
The Global Environment
Environments and Functions
Working with the Call Stack
Evaluating Functions in Different Environments
Adding Objects to an Environment
Exceptions
Signaling Errors
Catching Errors
Chapter 9. Functions
The Function Keyword
Arguments
Return Values
Functions As Arguments
Anonymous Functions
Properties of Functions
Argument Order and Named Arguments
Side Effects
Changes to Other Environments
Input/Output
Graphics
Chapter 10. Object-Oriented Programming
Overview of Object-Oriented Programming in R
Key Ideas
Implementation Example
Object-Oriented Programming in R: S4 Classes
Defining Classes
New Objects
Accessing Slots
Working with Objects
Creating Coercion Methods
Methods
Managing Methods
Basic Classes
More Help
Old-School OOP in R: S3
S3 Classes
S3 Methods
Using S3 Classes in S4 Classes
Finding Hidden S3 Methods
Chapter 11. High-Performance R
Use Built-in Math Functions
Use Environments for Lookup Tables
Use a Database to Query Large Data Sets
Preallocate Memory
Monitor How Much Memory You Are Using
Monitoring Memory Usage
Increasing Memory Limits
Cleaning Up Objects
Functions for Big Data Sets
Parallel Computation with R
High-Performance R Binaries
Revolution R
Building Your Own
Building on Microsoft Windows
Building R on Unix-like systems
Building R on Mac OS X
Part III. Working with Data
Chapter 12. Saving, Loading, and Editing Data
Entering Data Within R
Entering Data Using R Commands
Using the Edit GUI
Windows Data Editor
Mac OS X Data Editor
X Windows (Linux) Data Editor
Saving and Loading R Objects
Saving Objects with save
Importing Data from External Files
Text Files
Delimited files
Fixed-width files
Other functions to parse data
Other Software
Exporting Data
Importing Data from Databases
Export Then Import
Database Connection Packages
RODBC
Getting RODBC working
Installing the RODBC package
Installing ODBC drivers
Example: SQLite ODBC on Mac OS X
Example: SQLite ODBC on Windows
Using RODBC
Opening a channel
Getting information about the database
Getting data
DBI
Opening a connection
Getting DB information
Querying the database
Cleaning up
TSDBI
Chapter 13. Preparing Data
Combining Data Sets
Pasting Together Data Structures
Paste
rbind and cbind
An extended example
Merging Data by Common Fields
Transformations
Reassigning Variables
The Transform Function
Applying a Function to Each Element of an Object
Applying a function to an array
Applying a function to a list or vector
Binning Data
Shingles
Cut
Combining Objects with a Grouping Variable
Subsets
Bracket Notation
subset Function
Random Sampling
Summarizing Functions
tapply, aggregate
Aggregating Tables with rowsum
Counting Values
Reshaping Data
Transposing matrices and data frames
Reshaping data frames and matrices
Data Cleaning
Finding and Removing Duplicates
Sorting
Chapter 14. Graphics
An Overview of R Graphics
Scatter Plots
Plotting Time Series
Bar Charts
Pie Charts
Plotting Categorical Data
Three-Dimensional Data
Plotting Distributions
Box Plots
Graphics Devices
Customizing Charts
Common Arguments to Chart Functions
Graphical Parameters
Annotation
Margins
Multiple plots
Text properties
Text size
Line properties
Colors
Axes
Points
Typeface
Alignment and spacing
Rotation
Graphical parameter by name
Basic Graphics Functions
points
lines
curve
text
abline
polygon
segments
legend
title
axis
box
mtext
trans3d
Chapter 15. Lattice Graphics
History
An Overview of the Lattice Package
How Lattice Works
A Simple Example
Using Lattice Functions
Custom Panel Functions
High-Level Lattice Plotting Functions
Univariate Trellis Plots
Bar charts
Dot plots
Histograms
Density plots
Strip plots
Univariate quantile-quantile plots
Bivariate Trellis Plots
Scatter plots
Box plots in lattice
Scatter plots matrices
Bivariate quantile-quantile plots
Trivariate Plots
Level plots
Contour plots
Cloud plots
Wire-frame plots
Other Plots
Customizing Lattice Graphics
Common Arguments to Lattice Functions
trellis.skeleton
Controlling How Axes Are Drawn
Parameters
plot.trellis
strip.default
simpleKey
Low-Level Functions
Low-Level Graphics Functions
Panel Functions
Part IV. Statistics with R
Chapter 16. Analyzing Data
Summary Statistics
Correlation and Covariance
Principal Components Analysis
Factor Analysis
Bootstrap Resampling
Chapter 17. Probability Distributions
Normal Distribution
Common Distribution-Type Arguments
Distribution Function Families
Chapter 18. Statistical Tests
Continuous Data
Normal Distribution-Based Tests
Comparing means
Comparing paired data
Comparing variances of two populations
Comparing means across more than two groups
Pairwise t-tests between multiple groups
Testing for normality
Testing if a data vector came from an arbitrary distribution
Testing if two data vectors came from the same distribution
Correlation tests
Distribution-Free Tests
Comparing two means
Comparing more than two means
Comparing variances
Difference in scale parameters
Discrete Data
Proportion Tests
Binomial Tests
Tabular Data Tests
Distribution-Free Tabular Data Tests
Chapter 19. Power Tests
Experimental Design Example
t-Test Design
Proportion Test Design
ANOVA Test Design
Chapter 20. Regression Models
Example: A Simple Linear Model
Fitting a Model
Helper Functions for Specifying the Model
Getting Information About a Model
Viewing the model
Predicting values using a model
Analyzing the fit
Refining the Model
Details About the lm Function
Assumptions of Least Squares Regression
Robust and Resistant Regression
Resistant regression
Robust regression
Comparing lm, lqs, and rlm
Subset Selection and Shrinkage Methods
Stepwise Variable Selection
Ridge Regression
Lasso and Least Angle Regression
Principal Components Regression and Partial Least Squares Regression
Nonlinear Models
Generalized Linear Models
Nonlinear Least Squares
Survival Models
Smoothing
Splines
Fitting Polynomial Surfaces
Kernel Smoothing
Machine Learning Algorithms for Regression
Regression Tree Models
Recursive partitioning trees
Patient rule induction method
Bagging for regression
Boosting for regression
Random forests for regression
MARS
Neural Networks
Project Pursuit Regression
Generalized Additive Models
Support Vector Machines
Chapter 21. Classification Models
Linear Classification Models
Logistic Regression
Linear Discriminant Analysis
Log-Linear Models
Machine Learning Algorithms for Classification
k Nearest Neighbors
Classification Tree Models
Bagging
Boosting
Neural Networks
SVMs
Random Forests
Chapter 22. Machine Learning
Market Basket Analysis
Clustering
Distance Measures
Clustering Algorithms
Chapter 23. Time Series Analysis
Autocorrelation Functions
Time Series Models
Chapter 24. Bioconductor
An Example
Loading Raw Expression Data
Loading Data from GEO
Matching Phenotype Data
Analyzing Expression Data
Key Bioconductor Packages
Data Structures
eSet
AssayData
AnnotatedDataFrame
MIAME
Other Classes Used by Bioconductor Packages
Where to Go Next
Resources Outside Bioconductor
Vignettes
Courses
Books
Appendix. R Reference
base
Functions
Data Sets
boot
Functions
Data Sets
class
Functions
cluster
Functions
Data Sets
codetools
foreign
Functions
grDevices
Functions
Data Sets
graphics
Functions
grid
KernSmooth
Functions
lattice
Functions
Data Sets
MASS
Functions
Data Sets
methods
Functions
mgcv
nlme
nnet
Functions
rpart
Functions
Data Sets
spatial
Functions
splines
Functions
stats
Functions
Data Set
stats4
Functions
survival
Functions
Data Sets
tcltk
tools
Functions
Data Sets
utils
Functions
Bibliography
Index
R IN A NUTSHELL
R IN A NUTSHELL Joseph Adler Beijing•Cambridge•Farnham•Köln•Sebastopol•Taipei•Tokyo
R in a Nutshell by Joseph Adler Copyright © 2010 Joseph Adler. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more infor- mation, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com. Editor: Mike Loukides Production Editor: Sumita Mukherji Production Services: Newgen North America, Inc. Printing History: December 2009: First Edition. Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trade- marks of O’Reilly Media, Inc. R in a Nutshell, the image of a harpy eagle, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. This book uses RepKover™, a durable and flexible lay-flat binding. ISBN: 978-0-596-80170-0 [M] 1260894633 TM
Table of Contents Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv Part I. R Basics R Versions Getting and Installing Interactive R Binaries 1. Getting and Installing R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3 3 4 5 5 Windows Mac OS X Linux and Unix Systems The R Graphical User Interface Windows Mac OS X Linux and Unix 2. The R User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 7 8 8 8 11 13 13 14 15 Batch Mode Using R Inside Microsoft Excel Other Ways to Run R The R Console Command-Line Editing 3. A Short R Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 17 19 20 22 Basic Operations in R Functions Variables Introduction to Data Structures v
Objects and Classes Models and Formulas Charts and Graphics Getting Help 25 26 28 32 Loading Packages on Windows and Linux Loading Packages on Mac OS X An Overview of Packages Listing Packages in Local Libraries Loading Packages 4. R Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 35 36 38 38 38 39 40 40 43 43 45 Exploring Packages on the Web Finding and Installing Packages Inside R Creating a Package Directory Building the Package Exploring Package Repositories Custom Packages Part II. The R Language Expressions Objects Symbols Functions Objects Are Copied in Assignment Statements Everything in R Is an Object Special Values 5. An Overview of the R Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 49 50 50 50 52 52 53 53 53 54 54 54 55 57 NA Inf and -Inf NaN NULL Coercion The R Interpreter Seeing How R Works Constants Numeric Vectors Character Vectors Symbols Operators 6. R Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 61 61 62 63 64 65 67 67 Order of Operations Assignments Expressions vi | Table of Contents
分享到:
收藏