Tài liệu Exploring Everyday Things with R and Ruby pptx

251 591 0
Tài liệu Exploring Everyday Things with R and Ruby pptx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Exploring Everyday Things with R and Ruby Sau Sheong Chang 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 July 2012: Proofreader: Kiel Van Horn Indexer: Angela Howard Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano 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 ISBN: 978-1-449-31515-3 [LSI] Table of Contents Preface vii The Hat and the Whip Ruby Why Ruby Installing Ruby Running Ruby Requiring External Libraries Basic Ruby Everything Is an Object Shoes What Is Shoes? A Rainbow of Shoes Installing Shoes Programming Shoes Wrap-up 13 19 19 20 20 21 25 Into the Matrix 27 Introducing R Using R The R Console Sourcing Files and the Command Line Packages Programming R Variables and Functions Conditionals and Loops Data Structures Importing Data Charting Basic Graphs 27 28 29 31 33 35 36 37 39 46 51 51 iii Introducing ggplot2 Wrap-up 53 61 Offices and Restrooms 63 The Simple Scenario Representing Restrooms and Such The First Simulation Interpreting the Data The Second Simulation The Third Simulation The Final Simulation Wrap-up 64 66 69 73 79 83 88 91 How to Be an Armchair Economist 95 The Invisible Hand A Simple Market Economy The Producer The Consumer Some Convenience Methods The Simulation Analyzing the Simulation Resource Allocation by Price The Producer The Consumer Market The Simulation Analyzing the Second Simulation Price Controls Wrap-up 96 96 97 99 100 100 103 107 107 108 109 110 112 116 119 Discover Yourself Through Email 121 The Idea Grab and Parse The Emailing Habits of Enron Executives Discover Yourself Number of Messages by Day of the Month MailMiner Number of Messages by Day of Week Number of Messages by Month Number of Messages by Hour of the Day Interactions Comparative Interactions iv | Table of Contents 121 122 126 130 130 134 137 138 139 142 144 Text Mining Wrap-up 147 154 In a Heartbeat 157 My Beating Heart Auscultation Homemade Digital Stethoscope Extracting Data from Sound Generating the Heart Sounds Waveform Finding the Heart Rate Oximetry Homemade Pulse Oximeter Extracting Data from Video Generating the Heartbeat Waveform and Calculating the Heart Rate Wrap-up 157 158 158 159 164 166 168 168 169 172 174 Schooling Fish and Flocking Birds 177 The Origin of Boids Simulation Roids The Boid Flocking Rules Supporting Rules A Variation on the Rules Going Round and Round Putting in Obstacles Wrap-up 178 179 181 187 190 191 193 194 195 Money, Sex, and Evolution 197 It’s a Good Life Money Sex Birth and Death The Changes Evolution What We Will Be Changing Implementation Wrap-up 198 198 211 211 211 218 219 220 224 Index 227 Table of Contents | v Preface Explorers Ahoy! It’s hard to compare intrepid explorers like Ferdinand Magellan, James Cook, and Roald Amundsen with someone, well, like me While these adventurers braved the elements, wild nature, and unknown dangers to discover new worlds (at least for their civilization), my biggest physical achievement to date would probably be completing a 10-kilometer charity quarter-marathon—walking The explorers of old had it good, of course, when it came to choices of unexplored places to stake their claim on Christopher Columbus only had to sail due west from Europe, and he discovered two entire continents For us, there are far fewer choices There isn’t much landmass on Earth that is yet unexplored; even the Mariana Trench, the deepest part of the world’s oceans, has been conquered But explorer I am, and explorer you will be in this book While much of the known physical world has been conquered (see Figure P-1), the unknown still looms over most of us We are all born with a sense of wonder and amazement at the world around us Many of us just learn to turn it off as we grow older and jaded I believe this is partly because we don’t understand what goes on in the world around us well enough, and thus we don’t care either Click the remote and the TV turns on—why and how does that work? The first time we tried to ask, we were probably given a blank stare or waved away—who cares as long as you can watch the next season of American Idol? That soon grows to be our reaction as well vii Figure P-1 The Scott expedition to the South Pole (photo from the Public Domain Review; http://publicdomainreview.org/2012/03/29/remembering-scott) Well, in this book, I’ll take you along winding paths to bring back the original, wideeyed person you were We’ll find the magic again, and hopefully at the end of the book, you’ll continue where we leave off and make your own way in that journey of exploration and discovery Data, Data, Everywhere We are swamped with data every minute and second of our lives I don’t mean this metaphorically, and I am not simply waxing lyrical about big data either In fact, we’re so swamped that our eyes have evolved and adapted to this fact by shutting off our environment for a very short while every millisecond In a phenom­ enon called saccadic masking, the brain shuts down during a fast eye movement (a saccade) to remove blurred images that come to our retina Blurred images are not very useful, so the brain discards them, rendering us effectively blind (without us realizing it) during a saccade viii | Preface $roids

Ngày đăng: 15/02/2014, 07:20

Từ khóa liên quan

Mục lục

  • Copyright

  • Table of Contents

  • Preface

    • Explorers Ahoy!

    • Data, Data, Everywhere

    • Bringing the World to Us

    • Packing Your Bags

    • Conventions Used in This Book

    • Using Code Examples

    • Safari® Books Online

    • How to Contact Us

    • Acknowledgments

    • The Hat and the Whip

      • Ruby

        • Why Ruby

        • Installing Ruby

        • Running Ruby

        • Requiring External Libraries

        • Basic Ruby

        • Everything Is an Object

        • Shoes

          • What Is Shoes?

          • A Rainbow of Shoes

          • Installing Shoes

Tài liệu cùng người dùng

Tài liệu liên quan