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

Modern R Programming Cookbook

Book Description

Recipes for emerging developers in R programming and data scientists to simplify their R programming capabilities

About This Book

  • Develop strategies to speed up your R code
  • Tackle programming problems and explore both functional and object-oriented programming techniques
  • Learn how to address the core problems of programming in R with the most popular R packages for common tasks

Who This Book Is For

This book is for developers who would like to enhance the R programming skills. Basic knowledge of R programming is assumed.

What You Will Learn

  • Install R and its various IDE for a given platform along with installing libraries from different repositories and version control
  • Learn about basic data structures in R and how to work with them
  • Write customized R functions and handle recursions, exceptions in R environments
  • Create the data processing task as a step by step computer program and execute using dplyr
  • Extract and process unstructured text data
  • Interact with database management system to develop statistical applications
  • Formulate and implement parallel processing in R

In Detail

R is a powerful tool for statistics, graphics, and statistical programming. It is used by tens of thousands of people daily to perform serious statistical analyses. It is a free, open source system whose implementation is the collective accomplishment of many intelligent, hard-working people. There are more than 2,000 available add-ons, and R is a serious rival to all commercial statistical packages. The objective of this book is to show how to work with different programming aspects of R. The emerging R developers and data science could have very good programming knowledge but might have limited understanding about R syntax and semantics. Our book will be a platform develop practical solution out of real world problem in scalable fashion and with very good understanding. You will work with various versions of R libraries that are essential for scalable data science solutions. You will learn to work with Input / Output issues when working with relatively larger dataset. At the end of this book readers will also learn how to work with databases from within R and also what and how meta programming helps in developing applications.

Style and approach

This book will be a companion for R programmer and emerging developers in R programming areas. This book will contain recipes related to advanced R programming which will enable users to solve complex problems efficiently.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Conventions
    6. Reader feedback
    7. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Installing and Configuring R and its Libraries
    1. Introduction
    2. Installing and configuring base R in Windows
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
      5. See also
    3. Installing and configuring base R in Linux
      1. Getting ready
      2. How to do it...
      3. There's more...
      4. See also
    4. Installing and configuring RStudio IDE in Windows
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Installing and configuring RStudio IDE in Linux
      1. Getting ready
      2. How to do it…
      3. How it works...
      4. See also
    6. Installing and configuring R tools for Visual Studio in Windows
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. See also
    7. Installing R libraries from various sources
      1. Getting ready
      2. How to do it…
        1. The ggplot2 library
        2. The devtools library
        3. Installing a library from GitHub
        4. Installing a library from the BioC repository
      3. How it works…
      4. There's more…
      5. See also
    8. Installing a specific version of R library
      1. Getting ready
      2. How to do it…
      3. How it works…
  3. Data Structures in R
    1. Introduction
    2. Creating a vector and accessing its properties
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    3. Creating a matrix and accessing its properties
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    4. Creating a data frame and accessing its properties
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Creating an array and accessing its properties
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    6. Creating a list from a combination of vector, matrix, and data frame
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    7. Converting a matrix to a data frame and a data frame to a matrix
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
  4. Writing Customized Functions
    1. Introduction
    2. Writing your first function in R
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
    3. Writing functions with multiple arguments and use of default values
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
    4. Handling data types in input arguments
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
    5. Producing different output types and return values
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
    6. Making a recursive call to a function
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
    7. Handling exceptions and error messages
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
      5. See also
  5. Conditional and Iterative Operations
    1. Introduction
    2. The use of the if conditional statement
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
    3. The use of the if…else conditional operator
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
    4. The use of the ifelse vectorised conditional operator
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
      5. See also
    5. Writing a function using the switch operator
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
    6. Comparing the performance of switch and series of the if…else statements
      1. Getting ready
      2. How to do it…
      3. How it works…
    7. Using for loop for iterations
      1. Getting ready
      2. How to do it…
      3. How it works…
    8. Vectorised operation versus for loop
      1. Getting ready
      2. How to do it…
      3. How it works…
  6. R Objects and Classes
    1. Introduction
    2. Defining a new S3 class
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    3. Defining methods for the S3 class
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    4. Creating a generic function and defining a method for the S3 class
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    5. Defining a new S4 class
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    6. Defining methods for an S4 class
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    7. Creating a function to return an object of the S4 class
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
  7. Querying, Filtering, and Summarizing
    1. Introduction
    2. Using the pipe operator for data processing
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    3. Efficient and fast summarization using the dplyr verbs
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    4. Using the customized function within the dplyr verbs
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    5. Using the select verb for data processing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
      5. See also
    6. Using the filter verb for data processing
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using the arrange verb for data processing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
    8. Using mutate for data processing
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
    9. Using summarise to summarize dataset
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. R for Text Processing
    1. Introduction
    2. Extracting unstructured text data from a plain web page
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There’s more…
    3. Extracting text data from an HTML page
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    4. Extracting text data from an HTML page using the XML library
      1. Getting ready
      2. How to do it…
      3. How it works…
    5. Extracting text data from PubMed
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    6. Importing unstructured text data from a plain text file
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    7. Importing plain text data from a PDF file
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    8. Pre-processing text data for topic modeling and sentiment analysis
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    9. Creating a word cloud to explore unstructured text data
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    10. Using regular expression in text processing
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
  9. R and Databases
    1. Introduction
    2. Installing the PostgreSQL database server
      1. Getting ready
      2. How to do it…
      3. How it works…
    3. Creating a new user in the PostgreSQL database server
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    4. Creating a table in a database in PostgreSQL
      1. Getting ready
      2. How to do it...
      3. How it works…
      4. There's more…
    5. Creating a dataset in PostgreSQL from R
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Interacting with the PostgreSQL database from R
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more...
    7. Creating and interacting with the SQLite database from R
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more…
  10. Parallel Processing in R
    1. Introduction
    2. Creating an XDF file from CSV input
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    3. Processing data as a chunk
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    4. Comparing computation time with data frame and XDF
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    5. Linear regression with larger data (rxFastLiner)
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also