Preface

R is a powerful tool for statistics, graphics, and statistical programming. It is used by tens of thousands of people daily to perform serious statistical analyses. It is a free, open source system whose implementation is the collective accomplishment of many intelligent, hard-working people. There are more than 2,000 available add-ons, and R is a serious rival to all commercial statistical packages.

But R can be frustrating. It’s not obvious how to accomplish many tasks, even simple ones. The simple tasks are easy once you know how, yet figuring out the “how” can be maddening.

This is a book of how-to recipes for beginners, each of which solves a specific problem. The recipe includes a quick introduction to the solution, followed by a discussion that aims to unpack the solution and give you some insight into how it works. I know these recipes are useful and I know they work because I use them myself.

Most recipes use one or two R functions to solve the stated problem. It’s important to remember that I do not describe the functions in detail; rather, I describe just enough to get the job done. Nearly every such function has additional capabilities beyond those described here, and some of those capabilities are amazing. I strongly urge you to read the function’s help page. You will likely learn something valuable.

The book is not a tutorial on R, although you will learn something by studying the recipes. The book is not an introduction to statistics, either. The recipes assume that you are familiar with the underlying statistical procedure, if any, and just want to know how it’s done in R.

These recipes were taken from my R Cookbook (O’Reilly). The Cookbook contains over 200 recipes that you will find useful when you move beyond the basics of R.

Other Resources

I can recommend several other resources for R beginners:

An Introduction to R (Network Theory Limited)

This book by William N. Venables, et al., covers many general topics, including statistics, graphics, and programming. You can download the free PDF book; or, better yet, buy the printed copy because the profits are donated to the R project.

R in a Nutshell (O’Reilly)

Joseph Adler’s book is the tutorial and reference you’ll keep by your side. It covers many topics, from introductory material to advanced techniques.

Using R for Introductory Statistics (Chapman & Hall/CRC)

A good choice for learning R and statistics together by John Verzani. The book teaches statistical concepts together with the skills needed to apply them using R.

The R community has also produced many tutorials and introductions, especially in specialized topics. Most of this material is available on the Web, so I suggest searching there when you have a specific need (as in Recipe 1.4).

The R project website keeps an extensive bibliography of books related to R, both for beginning and advanced users.

Downloading Additional Packages

The R project has over 2,000 packages that you can download to augment the standard distribution with additional capabilities. You might see such packages mentioned in the See Also section of a recipe, or you might discover one while searching the Web.

Most packages are available through the Comprehensive R Archive Network (CRAN) at http://cran.r-project.org. From the CRAN home page, click on Packages to see the name and a brief description of every available package. Click on a package name to see more information, including the package documentation.

Downloading and installing a package is simple via the install.packages function. You would install the zoo package this way, for example:

> install.packages("zoo")

When R prompts you for a mirror site, select one near you. R will download both the package and any packages on which it depends, then install them onto your machine.

On Linux or Unix, I suggest having the systems administrator install packages into the system-wide directories, making them available to all users. If that is not possible, install the packages into your private directories.

Software and Platform Notes

The base distribution of R has frequent, planned releases, but the language definition and core implementation are stable. The recipes in this book should work with any recent release of the base distribution.

One recipe has platform-specific considerations (Recipe 1.1). As far as I know, all other recipes will work on all three major platforms for R: Windows, OS X, and Linux/Unix.

Conventions Used in This Book

The following typographical conventions are used in this book:

Italic

Indicates new terms, URLs, email addresses, filenames, and file extensions.

Constant width

Used for program listings, as well as within paragraphs to refer to program elements such as variable or function names, databases, data types, environment variables, statements, and keywords.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values or by values determined by context.

Tip

This icon signifies a tip, suggestion, or general note.

Caution

This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: “25 Recipes for Getting Started with R by Paul Teetor (O’Reilly). Copyright 2011 Paul Teetor, 978-1-449-30323-5.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Books Online

Note

Safari Books Online is an on-demand digital library that lets you easily search over 7,500 technology and creative reference books and videos to find the answers you need quickly.

With a subscription, you can read any page and watch any video from our library online. Read books on your cell phone and mobile devices. Access new titles before they are available for print, and get exclusive access to manuscripts in development and post feedback for the authors. Copy and paste code samples, organize your favorites, download chapters, bookmark key sections, create notes, print out pages, and benefit from tons of other time-saving features.

O’Reilly Media has uploaded this book to the Safari Books Online service. To have full digital access to this book and others on similar topics from O’Reilly and other publishers, sign up for free at http://my.safaribooksonline.com.

How to Contact Us

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/9781449303235

To comment or ask technical questions about this book, send email to:

For more information about our books, courses, conferences, and news, see our website at http://oreilly.com.

Find us on Facebook: http://facebook.com/oreilly

Follow us on Twitter: http://twitter.com/oreillymedia

Watch us on YouTube: http://www.youtube.com/oreillymedia

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset