Please enable JavaScript.
Coggle requires JavaScript to display documents.
(Hands-On Programming with R.pdf (Part III. Project 3: Slot Machine…
Hands-On Programming with R.pdf
R uses NULL to represent the null set, an empty object.
NULL is often returned by functions whose values are undefined.
NULL
In general, rows always come first in R
fill up the matrix column by column (default)
byrow = TRUE
data type is actually "double"
POSIXct :seconds that have passed between
the time and 12:00 AM January 1st 1970
unclass(now)
139505600
forcing the class of an object is a bad idea.
factor function: gender <- factor(c("male", "female", "male"))
recode the data
Add a levels attribute for the integer
R uses the levels attribute when it displays the factor,
factors can be confusing since they
look like character strings but behave like integers.
R will often try to convert character strings to factors when you load and create data.
Copyright
Table of Contents
Foreword
Preface
Conventions Used in This Book
Safari® Books Online
How to Contact Us
Acknowledgments
Part I. Project 1: Weighted Dice
Chapter 1. The Very Basics
The R User Interface
Objects
Functions
Sample with Replacement
Writing Your Own Functions
The Function Constructor
Arguments
Scripts
Summary
Chapter 2. Packages and Help Pages
Packages
install.packages
library
Getting Help with Help Pages
Parts of a Help Page
Getting More Help
Summary
Project 1 Wrap-up
Part II. Project 2: Playing Cards
Chapter 3. R Objects
Atomic Vectors
Doubles
Integers
Characters
Logicals
Complex and Raw
Attributes
Names
Dim
Matrices
Arrays
Class
Dates and Times
Factors
Coercion
Lists
Data Frames
Loading Data
Saving Data
Summary
Chapter 4. R Notation
Selecting Values
Positive Integers
Negative Integers
Zero
Blank Spaces
Logical Values
Names
Deal a Card
Shuffle the Deck
Dollar Signs and Double Brackets
Summary
Chapter 5. Modifying Values
Changing Values in Place
Logical Subsetting
Logical Tests
Boolean Operators
Missing Information
na.rm
is.na
Summary
Chapter 6. Environments
Environments
Working with Environments
The Active Environment
Scoping Rules
Assignment
Evaluation
Closures
Summary
Project 2 Wrap-up
Part III. Project 3: Slot Machine
Chapter 7. Programs
Strategy
Sequential Steps
Parallel Cases
if Statements
else Statements
Lookup Tables
Code Comments
Summary
Chapter 8. S3
The S3 System
Attributes
Generic Functions
Methods
Method Dispatch
Classes
S3 and Debugging
S4 and R5
Summary
Chapter 9. Loops
Expected Values
expand.grid
for Loops
while Loops
repeat Loops
Summary
Chapter 10. Speed
Vectorized Code
How to Write Vectorized Code
How to Write Fast for Loops in R
Vectorized Code in Practice
Loops Versus Vectorized Code
Summary
Project 3 Wrap-up
Appendix A. Installing R and RStudio
How to Download and Install R
Windows
Mac
Linux
Using R
RStudio
Opening R
Appendix B. R Packages
Installing Packages
Loading Packages
Appendix C. Updating R and Its Packages
R Packages
Appendix D. Loading and Saving Data in R
Data Sets in Base R
Working Directory
Plain-text Files
read.table
The read Family
read.fwf
HTML Links
Saving Plain-Text Files
Compressing Files
R Files
Saving R Files
Excel Spreadsheets
Export from Excel
Copy and Paste
XLConnect
Reading Spreadsheets
Writing Spreadsheets
Loading Files from Other Programs
Connecting to Databases
Appendix E. Debugging R Code
traceback
browser
Break Points
debug
trace
recover
Index
About the Author