Sau Sheong Chang
Exploring Everyday Things
with R and Ruby
Downloa d f r o m W o w ! e B o o k < w w w.woweb o o k . c o m >
ISBN: 978-1-449-31515-3
[LSI]
Exploring Everyday Things with R and Ruby
by Sau Sheong Chang
Copyright © 2012 Sau Sheong Chang. 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 information, contact our cor
porate/institutional sales department: 800-998-9938 or corporate@oreilly.com.
Editors: Andy Oram and Mike Hendrickson
Production Editor: Kristen Borg
Copyeditor: Rachel Monaghan
Proofreader: Kiel Van Horn
Indexer: Angela Howard
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrator: Robert Romano
July 2012: First Edition
Revision History for the First Edition:
2012-06-26 First release
See http://oreilly.com/catalog/errata.csp?isbn=9781449315153 for release details.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc.
Exploring Everyday Things with R and Ruby, the image of a hooded seal, 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 con
tained herein.
Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
1.
The Hat and the Whip. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Ruby 1
Why Ruby 2
Installing Ruby 3
Running Ruby 4
Requiring External Libraries 5
Basic Ruby 7
Everything Is an Object 13
Shoes 19
What Is Shoes? 19
A Rainbow of Shoes 20
Installing Shoes 20
Programming Shoes 21
Wrap-up 25
2.
Into the Matrix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Introducing R 27
Using R 28
The R Console 29
Sourcing Files and the Command Line 31
Packages 33
Programming R 35
Variables and Functions 36
Conditionals and Loops 37
Data Structures 39
Importing Data 46
Charting 51
Basic Graphs 51
iii
- 1
- 2
前往页