The Art of R Programming
A Tour of Statistical Software Design
Publisher: No Starch Press
Release Date: October 2011
Pages: 316
Read on Safari with a 10day trial
Start your free trial now Buy on AmazonWhere’s the cart? Now you can get everything on Safari. To purchase books, visit Amazon or your favorite retailer. Questions? See our FAQ or contact customer service:
18008898969 / 7078277019
support@oreilly.com
R is the world's most popular language for developing statistical software: Archaeologists use it to track the spread of ancient civilizations, drug companies use it to discover which medications are safe and effective, and actuaries use it to assess financial risks and keep economies running smoothly.
The Art of R Programming takes you on a guided tour of software development with R, from basic types and data structures to advanced topics like closures, recursion, and anonymous functions. No statistical knowledge is required, and your programming skills can range from hobbyist to pro.
Along the way, you'll learn about functional and objectoriented programming, running mathematical simulations, and rearranging complex data into simpler, more useful formats. You'll also learn to:
 Create artful graphs to visualize complex data sets and functions
 Write more efficient code using parallel R and vectorization
 Interface R with C/C++ and Python for increased speed or functionality
 Find new R packages for text analysis, image manipulation, and more
 Squash annoying bugs with advanced debugging techniques
Whether you're designing aircraft, forecasting the weather, or you just need to tame your data, The Art of R Programming is your guide to harnessing the power of statistical computing.
Table of Contents

Chapter 1 Getting Started

How to Run R

A First R Session

Introduction to Functions

Preview of Some Important R Data Structures

Extended Example: Regression Analysis of Exam Grades

Startup and Shutdown

Getting Help


Chapter 2 Vectors

Scalars, Vectors, Arrays, and Matrices

Declarations

Recycling

Common Vector Operations

Using all() and any()

Vectorized Operations

NA and NULL Values

Filtering

A Vectorized ifthenelse: The ifelse() Function

Testing Vector Equality

Vector Element Names

More on c()


Chapter 3 Matrices and Arrays

Creating Matrices

General Matrix Operations

Applying Functions to Matrix Rows and Columns

Adding and Deleting Matrix Rows and Columns

More on the Vector/Matrix Distinction

Avoiding Unintended Dimension Reduction

Naming Matrix Rows and Columns

HigherDimensional Arrays


Chapter 4 Lists

Creating Lists

General List Operations

Accessing List Components and Values

Applying Functions to Lists

Recursive Lists


Chapter 5 Data Frames

Creating Data Frames

Other MatrixLike Operations

Merging Data Frames

Applying Functions to Data Frames


Chapter 6 Factors and Tables

Factors and Levels

Common Functions Used with Factors

Working with Tables

Other Factor and TableRelated Functions


Chapter 7 R Programming Structures

Control Statements

Arithmetic and Boolean Operators and Values

Default Values for Arguments

Return Values

Functions Are Objects

Environment and Scope Issues

No Pointers in R

Writing Upstairs

Recursion

Replacement Functions

Tools for Composing Function Code

Writing Your Own Binary Operations

Anonymous Functions


Chapter 8 Doing Math and Simulations in R

Math Functions

Functions for Statistical Distributions

Sorting

Linear Algebra Operations on Vectors and Matrices

Set Operations

Simulation Programming in R


Chapter 9 ObjectOriented Programming

S3 Classes

S4 Classes

S3 Versus S4

Managing Your Objects


Chapter 10 Input/Output

Accessing the Keyboard and Monitor

Reading and Writing Files

Accessing the Internet


Chapter 11 String Manipulation

An Overview of StringManipulation Functions

Regular Expressions

Use of String Utilities in the edtdbg Debugging Tool


Chapter 12 Graphics

Creating Graphs

Customizing Graphs

Saving Graphs to Files

Creating ThreeDimensional Plots


Chapter 13 Debugging

Fundamental Principles of Debugging

Why Use a Debugging Tool?

Using R Debugging Facilities

Moving Up in the World: More Convenient Debugging Tools

Ensuring Consistency in Debugging Simulation Code

Syntax and Runtime Errors

Running GDB on R Itself


Chapter 14 Performance Enhancement: Speed and Memory

Writing Fast R Code

The Dreaded for Loop

Functional Programming and Memory Issues

Using Rprof() to Find Slow Spots in Your Code

Byte Code Compilation

Oh No, the Data Doesn’t Fit into Memory!


Chapter 15 Interfacing R to Other Languages

Writing C/C++ Functions to Be Called from R

Using R from Python


Chapter 16 Parallel R

The Mutual Outlinks Problem

Introducing the snow Package

Resorting to C

General Performance Considerations

Debugging Parallel R Code


Appendix Installing R

Downloading R from CRAN

Installing from a Linux Package Manager

Installing from Source


Appendix Installing and Using Packages

Package Basics

Loading a Package from Your Hard Drive

Downloading a Package from the Web

Listing the Functions in a Package


Colophon