Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
R Data Analysis Cookbook, Second Edition
R Data Analysis Cookbook, Second Edition

R Data Analysis Cookbook, Second Edition: Customizable R Recipes for data mining, data visualization and time series analysis , Second Edition

Arrow left icon
Profile Icon Kuntal Ganguly Profile Icon Viswanathan Profile Icon Viswa Viswanathan
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3 (4 Ratings)
Paperback Sep 2017 560 pages 2nd Edition
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon Kuntal Ganguly Profile Icon Viswanathan Profile Icon Viswa Viswanathan
Arrow right icon
€18.99 per month
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3 (4 Ratings)
Paperback Sep 2017 560 pages 2nd Edition
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

R Data Analysis Cookbook, Second Edition

What's in There - Exploratory Data Analysis

In this chapter, you will cover:

  • Creating standard data summaries
  • Extracting a subset of a dataset
  • Splitting a dataset
  • Creating random data partitions
  • Generating standard plots, such as histograms, boxplots, and scatterplots
  • Generating multiple plots on a grid
  • Creating plots with the lattice package
  • Creating charts that facilitate comparisons
  • Creating charts that help to visualize possible causality

Introduction

Exploratory analysis techniques are one part of the larger process of collecting data, learning from data, acting on data, and exploring data to uncover a meaningful pattern. The Exploratory Data Analysis (EDA) is a crucial step to take before diving into advanced analytics and machine learning, as it provides the context needed to develop an appropriate model for the problem at hand and to correctly interpret its results through visualization techniques to tease apart hidden patterns. In this chapter, we will discuss some of EDA's most common and essential practices, in order to summarize and visualize data so that the task of finding trends and patterns becomes causally easier.

Creating standard data summaries

In this recipe, we summarize the data using summary functions.

Getting ready

If you have not already downloaded the files for this chapter, do it now and ensure that the auto-mpg.csv file is in your R working directory.

How to do it...

Read the data from auto-mpg.csv, which includes a header row and columns separated by the default "," symbol.

  1. Read the data from auto-mpg.csv and convert cylinders to factor:
> auto  <- read.csv("auto-mpg.csv", header = TRUE,     stringsAsFactors = FALSE) 
> # Convert cylinders...

Extracting a subset of a dataset

In this recipe, we discuss two ways to subset data. The first approach uses the row and column indices/names and the other uses the subset() function.

Getting ready

Download the files for this chapter and store the auto-mpg.csv file in your R working directory. Read the data using the following command:

> auto <- read.csv("auto-mpg.csv", stringsAsFactors=FALSE) 

The same subsetting principles apply for vectors, lists, arrays, matrices, and data frames. We illustrate with data frames.

How to do it...

The following steps extract...

Splitting a dataset

When we have categorical variables, we often want to create groups corresponding to each level and to analyze each group separately to reveal some significant similarities and differences between them.

The split function divides data into groups based on a factor or vector. The unsplit() function reverses the effect of split.

Getting ready

Download the files for this chapter and store the auto-mpg.csv file in your R working directory. Read the file using the read.csv command and save in the auto variable:

> auto <- read.csv("auto-mpg.csv", stringsAsFactors=FALSE) 

How to do it...

...

Creating random data partitions

Analysts need an unbiased evaluation of the quality of their machine learning models. To get this, they partition the available data into two parts. They use one part to build the machine learning model and retain the remaining data as hold out data. After building the model, they evaluate the model's performance on the hold out data. This recipe shows you how to partition data. It separately addresses the situations when the target variable is numeric and when it is categorical. It also covers the process of creating two partitions or three.

Getting ready

If you have not already done so, make sure that the BostonHousing.csv and boston-housing-classification.csv files from the code files...

Generating standard plots, such as histograms, boxplots, and scatterplots

Before even embarking on any numerical analyses, you may want to get a good idea about the data through a few quick plots. The base R system supports basic graphics, so for more advanced plots requirement, we generally use lattice and ggplot packages. In this recipe we will cover the simplest form of basic graphs.

Getting ready

If you have not already done so, download the data files for this chapter and ensure that they are available in your R environment's working directory, and run the following commands:

> auto <- read.csv("auto-mpg.csv") 
>
> auto$cylinders <- factor(auto$cylinders, levels = c(3,4,5,6,8), labels...

Generating multiple plots on a grid

We often want to see plots side by side for comparisons. This recipe shows how we can achieve this.

Getting ready

If you have not already done so, download the data files for this chapter and ensure that they are available in your R environment's working directory. Once this is done, run the following commands:

> auto <- read.csv("auto-mpg.csv") 
> cylinders <- factor(cylinders, levels = c(3,4,5,6,8), labels = c("3cyl", "4cyl", "5cyl", "6cyl", "8cyl"))
> attach(auto)

How to do it...

...

Creating plots with the lattice package

The lattice package produces Trellis plots to capture multivariate relationships in the data. Lattice plots are useful for looking at complex relationships between the variables in a dataset. For example, we may want to see how y changes with x across various levels of z. Using the lattice package, we can draw histograms, boxplots, scatterplots, dot plots, and so on. Both plotting and annotation are done in one single call.

Getting ready

Download the files for this chapter and store the auto-mpg.csv file in your R working directory. Read the file using the read.csv function and save in the auto variable. Convert cylinders into a factor variable:

> auto <- read.csv("auto-mpg...

Creating charts that facilitate comparisons

In large datasets, we often gain good insights by examining how different segments behave. The similarities and differences can reveal interesting patterns. This recipe shows how to create graphs that enable such comparisons with different variable types.

Getting ready

If you have not already done so, download the book's files for this chapter and save the daily-bike-rentals.csv file in your R working directory. Read the data into R using
the following command and check the packages needed too:


> library(dplyr)

> bike <- read.csv("daily-bike-rentals.csv")
> bike$season <- factor(bike$season, levels = c(1,2,3,4),labels = c("Spring", "Summer...

Creating charts that help to visualize possible causality

When presenting data, rather than merely presenting information, we usually want to present an explanation of some phenomenon. Visualizing hypothesized causality helps to communicate our ideas clearly.

Getting ready

If you have not already done so, download the book's files for this chapter and save the hourly-bike-rentals.csv file in your R working directory. Read the data into R as follows:

> library(lattice)
> bike <- read.csv("daily-bike-rentals.csv")
> bike$season <- factor(bike$season, levels = c(1,2,3,4),
labels = c("Spring", "Summer", "Fall", "Winter"))
> bike$weathersit <- factor(bike...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Analyse your data using the popular R packages like ggplot2 with ready-to-use and customizable recipes
  • Find meaningful insights from your data and generate dynamic reports
  • A practical guide to help you put your data analysis skills in R to practical use

Description

Data analytics with R has emerged as a very important focus for organizations of all kinds. R enables even those with only an intuitive grasp of the underlying concepts, without a deep mathematical background, to unleash powerful and detailed examinations of their data. This book will show you how you can put your data analysis skills in R to practical use, with recipes catering to the basic as well as advanced data analysis tasks. Right from acquiring your data and preparing it for analysis to the more complex data analysis techniques, the book will show you how you can implement each technique in the best possible manner. You will also visualize your data using the popular R packages like ggplot2 and gain hidden insights from it. Starting with implementing the basic data analysis concepts like handling your data to creating basic plots, you will master the more advanced data analysis techniques like performing cluster analysis, and generating effective analysis reports and visualizations. Throughout the book, you will get to know the common problems and obstacles you might encounter while implementing each of the data analysis techniques in R, with ways to overcoming them in the easiest possible way. By the end of this book, you will have all the knowledge you need to become an expert in data analysis with R, and put your skills to test in real-world scenarios.

Who is this book for?

This book is for data scientists, analysts and even enthusiasts who want to learn and implement the various data analysis techniques using R in a practical way. Those looking for quick, handy solutions to common tasks and challenges in data analysis will find this book to be very useful. Basic knowledge of statistics and R programming is assumed.

What you will learn

  • Acquire, format and visualize your data using R
  • Using R to perform an Exploratory data analysis
  • Introduction to machine learning algorithms such as classification and regression
  • Get started with social network analysis
  • Generate dynamic reporting with Shiny
  • Get started with geospatial analysis
  • Handling large data with R using Spark and MongoDB
  • Build Recommendation system- Collaborative Filtering, Content based and Hybrid
  • Learn real world dataset examples- Fraud Detection and Image Recognition

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 20, 2017
Length: 560 pages
Edition : 2nd
Language : English
ISBN-13 : 9781787124479
Category :
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Sep 20, 2017
Length: 560 pages
Edition : 2nd
Language : English
ISBN-13 : 9781787124479
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 120.97
R Data Analysis Projects
€41.99
R Data Mining
€36.99
R Data Analysis Cookbook, Second Edition
€41.99
Total 120.97 Stars icon
Banner background image

Table of Contents

13 Chapters
Acquire and Prepare the Ingredients - Your Data Chevron down icon Chevron up icon
What's in There - Exploratory Data Analysis Chevron down icon Chevron up icon
Where Does It Belong? Classification Chevron down icon Chevron up icon
Give Me a Number - Regression Chevron down icon Chevron up icon
Can you Simplify That? Data Reduction Techniques Chevron down icon Chevron up icon
Lessons from History - Time Series Analysis Chevron down icon Chevron up icon
How does it look? - Advanced data visualization Chevron down icon Chevron up icon
This may also interest you - Building Recommendations Chevron down icon Chevron up icon
It's All About Your Connections - Social Network Analysis Chevron down icon Chevron up icon
Put Your Best Foot Forward - Document and Present Your Analysis Chevron down icon Chevron up icon
Work Smarter, Not Harder - Efficient and Elegant R Code Chevron down icon Chevron up icon
Where in the World? Geospatial Analysis Chevron down icon Chevron up icon
Playing Nice - Connecting to Other Systems Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.3
(4 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 25%
1 star 25%
Amazon Customer Oct 02, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The R Data Analysis Cookbook 2nd Edition is primarily focused on real life data analysis and data science activities performed by data analyst/data scientist using R and offers succinct examples on a variety of data analysis topics such as data cleaning & munging, exploratory analysis, vectorized operations, regression, classification, advance clustering, deep learning (image recognition), geospatial analysis, social network analysis, handling large dataset in R with Spark and MongoDB. I enjoyed the section dealing with classification, image recognition and R with distrbuted system. This book does not provide introduction to R language (as it assume the readers to have basic knowledge in R as prerequisite). Although the book provide brief explanation of the machine learning algorithms used in the recipes, with equation, how it works along with its pros/cons, but it doesn't explain in details or great depth about each of the machine learning algorthim. For such information, you will have to look elsewhere such as "Beginning R Programming" and "Machine Learning: An Algorithmic Perspective". Overall it a very good book and hits the road running, if you just have basic knowledge of R programming.
Amazon Verified review Amazon
John DCousta Oct 16, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is for data analyst and aspiring data science professionals who are familiar with basics of R and want to expand their skill set in data analysis activities (without diving too much into mathematics/statistical jargon)- data cleaning & munging, eda, machine learning such as- regression, classification, advance clustering, deep learning (image recognition), handling large dataset in R with Spark.
Amazon Verified review Amazon
Leonardo Damasceno Dec 11, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Did not like. Too superficial. Treat each topic as 'cake recipe'.
Amazon Verified review Amazon
Dimitri Shvorob Dec 07, 2017
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Looking at the five-star reviews, I notice that "John DCousta" has only reviewed, and given five-star reviews, to Ganguly's two (Packt) books, and "Alessandro Breschi" - whose profile initially had name "Sunith Shetty" - has similarly only reviewed, and given five-star reviews, to three Packt books, one of them plagiarized. In all likelihood, both reviews are fake. Another thing you should know is that Ganguly's other book, "Learning Generative Adversarial Networks", is plagiarized. Even if this one isn't - which I think is unlikely - you should not support a plagiarist by buying his books.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.