实例介绍
A good handbook for learning R.
INA NUTSHELL Second edition Joseph adler ○ REILLY° Beijing· Cambridge· Farnham·Koln· Sebastopol· Tokyo Rin a nutshell second edition by Joseph adler Copyright o 2012 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 editionsarealsoavailableformosttitles(http://my.safaribooksonline.com).Formoreinfor mation, contact our corporate/institutional sales department: 800-998-9938or corporateaoreilly.com Editors: Mike Loukides and Meghan Blanchette Indexer: Fred Brown Production Editor: Holly bauer Cover Designer: Karen Montgomer Proofreader: Julie Van Keuren Interior Designer: David Futato illustrators: Robert romano and re- becca demarest September 2009: First Edition October 2012 Second edition Revision History for the Second Edition 201209-25 First release Seehttporeillycom/catalog/errata.cspisbn=9781449312084forreleasedetails 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 ISBN:978-1-449-31208-4 [LSI 1348585490 Table of contents Preface XIl Part. r basics Getting and Installing..,.........,...... R Versions Getting and Installing interactive binaries Windows Mac os X Linux and Unix Systems 3334557 2. The r user interface The R graphical user Interface Windows Mac os X Linux and unix Ther Console Command-Line editing Batch mode Using R Inside Microsoft Excel 334 STudio 15 Other ways to run r 3. a Short r tutoria Basic Operations in r 19 Functions 21 b ariables 22 Ⅲ Introduction to data structures 24 Objects and classes 27 Models and formulas 28 Charts and graphics 30 ng Hel 4. PAckages...... 37 An Overview of Packages Listing Packages in Local Libraries 38 oading Packages 40 Loading Packages on Windows and Linux Loading Packages on Mac OsX 40 Exploring Package Repositories 41 Exploring r package Repositories on the web Finding and Installing Packages Inside r 42 Installing Packages From Other Repositories 45 Custom Packages 45 Creating a Package directory 45 Building the package Part I. The r language 5. An Overview of the r language 51 Expressions Objects Symbols Functions Objects Are Copied in Assignment Statements 54 Everything in R Is an Ob Values pecial va NA 56 NULL The R Interpreter Seeing How Works 59 6. R Syntax 63 Constants 63 Numeric vectors 63 Character vectors 64 65 Operators 66 Order of operations 67 iv Table of Contents assignments Expressions Separating expressions Parentheses 66677 99900 urly Braces Control structures 71 Conditional statements Accessing Data Structures Data Structure operators Indexing by Integer Vector 76 Indexing by Logical Vector 78 Indexing by name 79 R Code style standard 7. OBjects ,83 Primitive Object Types 83 Vectors Lists Other objects Matrices 8888 Array Factors 89 Data frames 91 Formulas Time series 94 Shingles Dates and times 95 Connections Attributes ass 99 8. Symbols and environments 101 Symbo 101 Working with environments The Global environment 103 Environments and Functions 104 Working with the Call Stack 104 Evaluating Functions in Different Environments Adding objects to an environment 107 Exceptions 108 Signaling erro ors 108 Catching Errors 109 9. Functions∴ The Function Keyword Table of Contents I arguments R 113 Functions as arguments 113 Anonymous functions 114 Properties of Functions 115 Argument Order and Named arguments 117 Side effects 118 Changes to Other Environments 118 Input/Output 119 hi rapl 10. Object-Oriented Programming....... .......... 121 Overview of Object-Oriented Programming in R y Ideas mplementation Example Object-Oriented Programming in R: S4 Classes Defining Classes New Objects 130 Accessing Slots 130 king with obj Creating Coercion Methods 131 133 Basic cl 134 More Help 135 Old-School oop in r:S3 135 asses 135 S3 Methods 136 Using $3 Classes in S4 Classes 137 Finding Hidden $3 Methods 137 Part ll.Working with Data 11. Saving, Loading, and Editing Data 141 Entering Data Within R 141 Entering data Using R commands 141 Using the Edit guI 14 Saving and Loading r Objects 145 Saving Objects with sav Importing Data from External Files 146 Text file Other Software 154 Exporting Data 155 Importing data From Databases 156 Export Then import 15 vi Table of〔 ontents atabase connection Packages 156 RODBC DBI 6 TSDBI 172 etting Data from Hadoop 172 12. Preparing Data 173 Combining data Sets Pasting Together Data Structures 174 Merging Data by Common Fields Transformations 179 Reassigning variables 179 The transform function Applying a Function to Each Element of an Object 180 Binning data 185 singles 185 186 Combining Objects with a Grouping Variable 187 upsets 8 Bracket notation 188 subset Function andom sampling 189 ummarizing Functions 190 tapply, aggregate 190 Aggregating tables with rowsum 193 Counting values 194 Reshaping data Data Cleaning 205 Finding and Removing duplicates 205 Sorting 206 Part v. data visualization 13. Graphics An Overview of R graphics 213 Scatter plots 214 Plotting Time Series 220 Bar charts 222 Pie charts 226 Plotting Categorical Data 227 Three-Dimensional data 232 Plotting Distributions 239 Box Plots 242 Graphics Devices 246 Customizing charts 247 Table of contents|ⅶi Common arguments to Chart Functions 247 Graphical Parameters 247 Basic graphics functions 257 14. Lattice Graphics 267 Histe 267 An Overview of the Lattice Package 268 lAttice works 268 A Simple example 268 U Lattice fu 270 Custom Panel functions 272 High-Level Lattice Plotting Functions 272 Univariate Trellis plots 273 Bivariate trellis plots 297 Trivariate plots 305 Other plots 310 Customizing lattice Graphics 312 Common Arguments to Lattice Functions 312 trellis skeleton 313 Controlling How Axes Are Drawn 314 Parameters 315 pl t trellis 319 strip. default 320 simplexes 321 Low-Level functions 322 Low-Level Graphics Functions 322 Panel functions 323 15. ggplot A Short introduction 325 The grammar of graphics 328 A More Complex example: medicare Data 333 Quick plot 342 Creating Graphics with ggplot2 343 Learning more 347 Part v. Statistics with r 16. analyzing Data.......... n351 Summary statistics 351 Correlation and Covariance 354 Principal components analysis 357 Factor Analysis 360 Bootstrap resampling 361 ⅶ ii Table of Contents 【实例截图】
【核心代码】
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论