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
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
€41.99
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
€41.99
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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
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
Estimated delivery fee Deliver to Cyprus

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Cyprus

Premium delivery 7 - 10 business days

€32.95
(Includes tracking information)

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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela