O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

R Object-oriented Programming

Book Description

A practical guide to help you learn and understand the programming techniques necessary to exploit the full power of R

In Detail

R is best suited to produce data and visual analytics through customizable scripts and commands, instead of typical statistical tools that provide tick boxes and drop-down menus for users. The book is divided into three parts to help you perform these steps. It starts by providing you with an overview of the basic data types, data structures, and tools available in R that are used to solve common tasks. It then moves on to offer insights and examples on object-oriented programming with R; this includes an introduction to the basic control structures available in R with examples. It also includes details on how to implement S3 and S4 classes. Finally, the book provides three detailed examples that demonstrate how to bring all of these ideas together.

What You Will Learn

  • Understand the fundamental data types and data structures in R
  • Explore the basic commands and tools to aid in addressing common tasks
  • Use the primary control structures in R to implement algorithms
  • Use and develop S3 and S4 classes
  • Discover the differences between S3 and S4 classes
  • Bring different ideas together to solve common problems
  • Understand the fundamental design and approach to object-oriented programming in R

Table of Contents

  1. R Object-oriented Programming
    1. Table of Contents
    2. R Object-oriented Programming
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Copyright violations
        4. Questions
    8. 1. Data Types
      1. Assignment
      2. The workspace
      3. Discrete data types
        1. Integer
        2. Logical
          1. Character
          2. Factors
        3. Continuous data types
          1. Double
          2. Complex
        4. Special data types
          1. Notes on the as and is functions
      4. Summary
    9. 2. Organizing Data
      1. Basic data structures
        1. Vectors
        2. Lists
        3. Data frames
        4. Tables
        5. Matrices and arrays
        6. Censoring data
        7. Appending rows and columns
      2. Operations on data structures
        1. The apply commands
          1. apply
          2. lapply and sapply
          3. tapply
          4. mapply
      3. Summary
    10. 3. Saving Data and Printing Results
      1. File and directory information
      2. Entering data
        1. Entering data from the command line
        2. Reading tables from files
        3. CSV files
        4. Fixed-width files
      3. Printing results and saving data
        1. Saving a workspace
        2. The cat command
        3. The print, format, and paste commands
      4. Primitive input/output
      5. Network options
        1. Opening a socket
        2. Basic socket operations
      6. Summary
    11. 4. Calculating Probabilities and Random Numbers
      1. Overview
        1. Distribution functions
        2. Cumulative distribution functions
        3. Inverse cumulative distribution functions
        4. Generating pseudorandom numbers
        5. Sampling
        6. Summary
    12. 5. Character and String Operations
      1. Basic string operations
      2. Six focused tasks
        1. Determining the length of a string
        2. Location of a substring
        3. Extracting or changing a substring
        4. Transforming the case
        5. Splitting strings
        6. Creating formatted strings
      3. Regular expressions
      4. Summary
    13. 6. Converting and Defining Time Variables
      1. Introduction and assumptions
      2. Converting strings to time data types
        1. Converting time data types to strings
        2. Operations on time data types
      3. Summary
    14. 7. Basic Programming
      1. Conditional execution
        1. Loop constructs
          1. The for loop
          2. The while loop
          3. The repeat loop
          4. Break and next statements
        2. Functions
          1. Defining a function
          2. Arguments to functions
          3. Scope
        3. Executing scripts
      2. Summary
    15. 8. S3 Classes
      1. Defining classes and methods
      2. Defining objects and inheritance
      3. Encapsulation
      4. A final note
      5. Summary
    16. 9. S4 Classes
      1. Introducing the Ant class
      2. Defining an S4 class
      3. Defining methods for an S4 class
        1. Defining new methods
        2. Polymorphism
        3. Extending the existing methods
      4. Inheritance
      5. Miscellaneous notes
      6. Summary
    17. 10. Case Study – Course Grades
      1. Overview
      2. The Course class
        1. The definition of the Course class
        2. Reading grades from a file
      3. The assignment classes
        1. The NumericGrade class
        2. The LetterGrade class
        3. Example – reading grades from a file
      4. Defining indexing operations
      5. Redefining existing functions
      6. Redefining arithmetic operations
      7. Summary
    18. 11. Case Study – Simulation
      1. The simulation classes
      2. The Monte-Carlo class
      3. Examples
      4. Summary
    19. A. Package Management
    20. Index