Cover image for Hands-On Programming with R

Book description

Learn how to program by diving into the R language, and then use your newfound skills to solve practical data science problems. With this book, you’ll learn how to load data, assemble and disassemble data objects, navigate R’s environment system, write your own functions, and use all of R’s programming tools.

Table of Contents

  1. Foreword
  2. Preface
    1. Conventions Used in This Book
    2. Safari® Books Online
    3. How to Contact Us
    4. Acknowledgments
  3. I. Project 1: Weighted Dice
    1. 1. The Very Basics
      1. The R User Interface
      2. Objects
      3. Functions
      4. Sample with Replacement
      5. Writing Your Own Functions
        1. The Function Constructor
      6. Arguments
      7. Scripts
      8. Summary
    2. 2. Packages and Help Pages
      1. Packages
        1. install.packages
        2. library
      2. Getting Help with Help Pages
        1. Parts of a Help Page
        2. Getting More Help
      3. Summary
      4. Project 1 Wrap-up
  4. II. Project 2: Playing Cards
    1. 3. R Objects
      1. Atomic Vectors
        1. Doubles
        2. Integers
        3. Characters
        4. Logicals
        5. Complex and Raw
      2. Attributes
        1. Names
        2. Dim
      3. Matrices
      4. Arrays
      5. Class
        1. Dates and Times
        2. Factors
      6. Coercion
      7. Lists
      8. Data Frames
      9. Loading Data
      10. Saving Data
      11. Summary
    2. 4. R Notation
      1. Selecting Values
        1. Positive Integers
        2. Negative Integers
        3. Zero
        4. Blank Spaces
        5. Logical Values
        6. Names
      2. Deal a Card
      3. Shuffle the Deck
      4. Dollar Signs and Double Brackets
      5. Summary
    3. 5. Modifying Values
      1. Changing Values in Place
      2. Logical Subsetting
        1. Logical Tests
        2. Boolean Operators
      3. Missing Information
        1. na.rm
        2. is.na
      4. Summary
    4. 6. Environments
      1. Environments
      2. Working with Environments
        1. The Active Environment
      3. Scoping Rules
      4. Assignment
      5. Evaluation
      6. Closures
      7. Summary
      8. Project 2 Wrap-up
  5. III. Project 3: Slot Machine
    1. 7. Programs
      1. Strategy
        1. Sequential Steps
        2. Parallel Cases
      2. if Statements
      3. else Statements
      4. Lookup Tables
      5. Code Comments
      6. Summary
    2. 8. S3
      1. The S3 System
      2. Attributes
      3. Generic Functions
      4. Methods
        1. Method Dispatch
      5. Classes
      6. S3 and Debugging
      7. S4 and R5
      8. Summary
    3. 9. Loops
      1. Expected Values
      2. expand.grid
      3. for Loops
      4. while Loops
      5. repeat Loops
      6. Summary
    4. 10. Speed
      1. Vectorized Code
      2. How to Write Vectorized Code
      3. How to Write Fast for Loops in R
      4. Vectorized Code in Practice
        1. Loops Versus Vectorized Code
      5. Summary
      6. Project 3 Wrap-up
    5. A. Installing R and RStudio
      1. How to Download and Install R
        1. Windows
        2. Mac
        3. Linux
      2. Using R
      3. RStudio
      4. Opening R
    6. B. R Packages
      1. Installing Packages
      2. Loading Packages
    7. C. Updating R and Its Packages
      1. R Packages
    8. D. Loading and Saving Data in R
      1. Data Sets in Base R
      2. Working Directory
      3. Plain-text Files
        1. read.table
          1. sep
          2. header
          3. na.strings
          4. skip and nrow
          5. stringsAsFactors
        2. The read Family
        3. read.fwf
        4. HTML Links
        5. Saving Plain-Text Files
        6. Compressing Files
      4. R Files
        1. Saving R Files
      5. Excel Spreadsheets
        1. Export from Excel
        2. Copy and Paste
        3. XLConnect
        4. Reading Spreadsheets
        5. Writing Spreadsheets
      6. Loading Files from Other Programs
        1. Connecting to Databases
    9. E. Debugging R Code
      1. traceback
      2. browser
      3. Break Points
      4. debug
      5. trace
      6. recover
  6. Index
  7. Colophon
  8. Copyright