SlideShare a Scribd company logo
1 of 18
dplyr Package
Introduction
Helps transform and manipulate data
Powerful tool to summarise data sets
Install: install.packages(dplyr)
Activate: library(dplyr)
File: Excel
Variables: 7
Observations: 153
▪ select
▪ filter
▪ arrange
▪ distinct
▪ mutate
▪ transmute
▪ group_by
▪ summarise
▪ pipe operator (%>%)
▪ slice
▪ count
Functions in dplyr
• Keeps only those variables (columns) that you
want to retain/extract.
• Syntax: select(dataset,[column1],[column2],…)
Examples:
 Select columns Month, Dealer, Item, Quantity: select(sales,Month,Dealer,Item,Qty)
 Select columns from Month to Quantity: select(sales,Month:Qty)
 Deselect column Month from the dataset: select(sales,-Month)
 Select columns ending with the letter “r”: select(sales,ends_with("r"))
 Select columns containing the letter “r”: select(sales,contains("r"))
 Select columns starting the series “m”: select(sales,matches("m."))
 Select columns with multiple variables: select(sales,one_of(c("Month","Dealer")))
 Select columns starting with the letter “d”: select(sales,starts_with("d"))
select()
• Keeps only those records (rows) that you want to
retain/extract.
• Syntax: filter(dataset,criteria)
Examples:
 Item is Pen: filter(sales,Item==“Pen”)
 Quantity is more than 50: filter(sales,Qty>50)
 Item is Pencil and Quantity is more than 50: filter(sales,Item=="Pencil"&Qty>50)
 Quantity is between 50 and 80: filter(sales,Qty>50&Qty<80)
 Item is Pencil or Quantity is more than 50: filter(sales,Item=="Pencil"|Qty>50)
filter()
Examples:
 We want to extract the Sales Manager, Item and Quantity but only for Pencil:
i) k=select(sales,SalesManager,Item,Qty)
filter(k,Item=="Pencil")
ii) select(filter(sales,Item=="Pencil"),SalesManager,Item,Qty)
iii) filter(select(sales,SalesManager,Item,Qty),Item=="Pencil")
 We want to extract for the Month of May, Dealer, Item and Quantity:
i) filter(select(sales,Dealer,Item,Qty),sales$Month=="May")
ii) filter(select(sales,Dealer,Item,Qty),Month=="May")
select() and filter()
• Orders or sorts the records (rows) based on the
variable(s).
• By default the arrangement is in ascending order.
• Syntax: arrange(dataset,column1,[column2],…)
Examples:
 Sort the dataset based on Months: arrange(sales,Month)
 Sort the dataset based on Months and Dealer: arrange(sales,Month,Dealer)
 Arrange the data in descending order of Quantity: arrange(sales,desc(Qty))
arrange()
• Helps extract unique values from a variable.
• Syntax: distinct(dataset,by=column1)
Examples:
 Find the names of the Dealers: distinct(sales,Dealer)
 Find the items sold by each Dealer: arrange(distinct(sales,Dealer,Item),by=Dealer)
distinct()
• Adds a new variable (column) to the existing
dataset
• Syntax: mutate(dataset,newcolumn=criteria)
Example:
 Add a new column Target where it is twice of Quantity: mutate(sales,Target=Qty*2)
mutate()
• Creates a new variable (column) but drops the
existing ones
• Syntax: transmute(dataset,newcolumn=criteria)
Example:
 Create a new column Target where it is twice of Quantity: transmute(sales,tgt=2*Qty)
transmute()
• Helps create groups in a dataset based on a
varaible.
• Useful when nested with other functions.
• Syntax: group_by(dataset,column1,[column2]…)
• Ungroup Syntax: ungroup(dataset)
Example:
 Create groups in the data based on Items: group_by(sales,Item)
 Get the maximum units sold for each item: filter(group_by(sales,by=Item),Qty==max(Qty))
group_by()
• Helps generate a single number/statistic for the dataset
• Syntax: summarise(dataset,newvariable=function….)
Examples:
 Total number of units sold across all Items:
summarise(sales,total=sum(Qty))
 Total number of units sold and total amount:
summarise(sales,t_Qty=sum(Qty),t_Amount=sum(Amount))
 Total number of records in the dataset:
summarise(sales,rowscount=n())
 Get the total number of records, quantity sold and amount for each item:
summarise(group_by(sales,Item),rcount=n(),untiyqty=sum(Qty),totalamount=sum(Amount))
 Every statistic for each dealer and their respective items:
summarise(group_by(sales,Dealer,Item),rcount=n(),untiyqty=sum(Qty),totalamount=sum(Amount))
summarise()
 We want to extract the top 6 records for Dealers who have sold the Item Pen only:
filter((sales,Item=="Pen")
select(filter(sales,Item=="Pen"),Item,Dealer,Qty)
arrange(select(filter(sales,Item=="Pen"),Item,Dealer,Qty),by=Dealer)
head(arrange(select(filter(sales,Item=="Pen"),Item,Dealer,Qty),by=Dealer))
 We want the maximum quantity of every item for the month of May with just Dealer, Item and
Quantity variables:
select(sales,Dealer,Item,Qty)
filter(select(sales,Dealer,Item,Qty),sales$Month=="May")
group_by(filter(select(sales,Dealer,Item,Qty),sales$Month=="May"),Item,Dealer)
summarise(group_by(filter(select(sales,Dealer,Item,Qty),sales$Month=="May"),Item,Dealer),max(Qty))
Assignment
• Belongs to magrittr Package.
• Helps structure sequence of operations in a
single code from left to right.
• Helps avoid nesting of funtions.
• Operator: %>%
Examples:
 We want to extract the top 6 records for Dealers who have sold the Item Pen only:
sales%>%filter(Item=="Pen")%>%select(Dealer,Item,Qty)%>%arrange(Dealer)%>%head
 We want the maximum quantity of every item for the month of May with just Dealer, Item and
Quantity variables:
sales%>%select(Dealer,Item,Qty)%>%filter(sales$Month=="May")%>%group_by(Item,Dealer)%>%sum
marise(max(Qty))
pipe operator %>%
• Helps extract records (rows) based on their
position.
• Syntax: slice(dataset,row numbers)
Examples:
 Select first ten rows: slice(sales,1:10)
 Select rows fifteen to twenty: slice(sales,15:20)
slice()
• Helps count the number of times a values has
appeared in a variable.
• Syntax: count(dataset, [column1],[column2],…)
Examples:
 Count the number of times each Dealer has appeared: count(sales,Dealer)
 Count the number of times Pen has appeared: count(sales,Item=="Pen")
count()
Thanks!
Any questions?
You can find me at
▪ cc@wkvedu.com

More Related Content

What's hot

Exploratory data analysis with Python
Exploratory data analysis with PythonExploratory data analysis with Python
Exploratory data analysis with PythonDavis David
 
1.2 steps and functionalities
1.2 steps and functionalities1.2 steps and functionalities
1.2 steps and functionalitiesKrish_ver2
 
Data preprocessing in Machine learning
Data preprocessing in Machine learning Data preprocessing in Machine learning
Data preprocessing in Machine learning pyingkodi maran
 
Exploratory Data Analysis
Exploratory Data AnalysisExploratory Data Analysis
Exploratory Data AnalysisUmair Shafique
 
Data preprocessing in Data Mining
Data preprocessing in Data MiningData preprocessing in Data Mining
Data preprocessing in Data MiningDHIVYADEVAKI
 
Classification and prediction in data mining
Classification and prediction in data miningClassification and prediction in data mining
Classification and prediction in data miningEr. Nawaraj Bhandari
 
Data Integration and Transformation in Data mining
Data Integration and Transformation in Data miningData Integration and Transformation in Data mining
Data Integration and Transformation in Data miningkavitha muneeshwaran
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In RRsquared Academy
 
Data visualization using R
Data visualization using RData visualization using R
Data visualization using RUmmiya Mohammedi
 
Data mining presentation.ppt
Data mining presentation.pptData mining presentation.ppt
Data mining presentation.pptneelamoberoi1030
 
Data Mining:Concepts and Techniques, Chapter 8. Classification: Basic Concepts
Data Mining:Concepts and Techniques, Chapter 8. Classification: Basic ConceptsData Mining:Concepts and Techniques, Chapter 8. Classification: Basic Concepts
Data Mining:Concepts and Techniques, Chapter 8. Classification: Basic ConceptsSalah Amean
 
Frequent itemset mining methods
Frequent itemset mining methodsFrequent itemset mining methods
Frequent itemset mining methodsProf.Nilesh Magar
 

What's hot (20)

02 data
02 data02 data
02 data
 
Exploratory data analysis with Python
Exploratory data analysis with PythonExploratory data analysis with Python
Exploratory data analysis with Python
 
K Nearest Neighbors
K Nearest NeighborsK Nearest Neighbors
K Nearest Neighbors
 
1.2 steps and functionalities
1.2 steps and functionalities1.2 steps and functionalities
1.2 steps and functionalities
 
Data preprocessing in Machine learning
Data preprocessing in Machine learning Data preprocessing in Machine learning
Data preprocessing in Machine learning
 
Data Preprocessing
Data PreprocessingData Preprocessing
Data Preprocessing
 
Exploratory Data Analysis
Exploratory Data AnalysisExploratory Data Analysis
Exploratory Data Analysis
 
Data preprocessing in Data Mining
Data preprocessing in Data MiningData preprocessing in Data Mining
Data preprocessing in Data Mining
 
Classification and prediction in data mining
Classification and prediction in data miningClassification and prediction in data mining
Classification and prediction in data mining
 
DBMS Keys
DBMS KeysDBMS Keys
DBMS Keys
 
Data Integration and Transformation in Data mining
Data Integration and Transformation in Data miningData Integration and Transformation in Data mining
Data Integration and Transformation in Data mining
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In R
 
Data visualization using R
Data visualization using RData visualization using R
Data visualization using R
 
Data mining presentation.ppt
Data mining presentation.pptData mining presentation.ppt
Data mining presentation.ppt
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Data preprocessing ng
Data preprocessing   ngData preprocessing   ng
Data preprocessing ng
 
Data Mining:Concepts and Techniques, Chapter 8. Classification: Basic Concepts
Data Mining:Concepts and Techniques, Chapter 8. Classification: Basic ConceptsData Mining:Concepts and Techniques, Chapter 8. Classification: Basic Concepts
Data Mining:Concepts and Techniques, Chapter 8. Classification: Basic Concepts
 
Frequent itemset mining methods
Frequent itemset mining methodsFrequent itemset mining methods
Frequent itemset mining methods
 
Clustering
ClusteringClustering
Clustering
 
Assosiate rule mining
Assosiate rule miningAssosiate rule mining
Assosiate rule mining
 

Similar to dplyr Package in R

Getting Started with MDX 20140625a
Getting Started with MDX 20140625aGetting Started with MDX 20140625a
Getting Started with MDX 20140625aRon Moore
 
Data mining 3 - Data Models and Data Warehouse Design (cheat sheet - printable)
Data mining  3 - Data Models and Data Warehouse Design (cheat sheet - printable)Data mining  3 - Data Models and Data Warehouse Design (cheat sheet - printable)
Data mining 3 - Data Models and Data Warehouse Design (cheat sheet - printable)yesheeka
 
Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to daxIke Ellis
 
Adding measures to Calcite SQL
Adding measures to Calcite SQLAdding measures to Calcite SQL
Adding measures to Calcite SQLJulian Hyde
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolioguest3ea163
 
Introduction - Using Stata
Introduction - Using StataIntroduction - Using Stata
Introduction - Using StataRyan Herzog
 
Oracle sql analytic functions
Oracle sql analytic functionsOracle sql analytic functions
Oracle sql analytic functionsmamamowebby
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine LearningAmanBhalla14
 
CS 151 Standard deviation lecture
CS 151 Standard deviation lectureCS 151 Standard deviation lecture
CS 151 Standard deviation lectureRudy Martinez
 
Company segmentation - an approach with R
Company segmentation - an approach with RCompany segmentation - an approach with R
Company segmentation - an approach with RCasper Crause
 
Calculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdfCalculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdfPBIMINERADC
 
4. chapter iv(transform)
4. chapter iv(transform)4. chapter iv(transform)
4. chapter iv(transform)Chhom Karath
 
IT301-Datawarehousing (1) and its sub topics.pptx
IT301-Datawarehousing (1) and its sub topics.pptxIT301-Datawarehousing (1) and its sub topics.pptx
IT301-Datawarehousing (1) and its sub topics.pptxReneeClintGortifacio
 
Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data ScientistsDatabricks
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxprakashvs7
 

Similar to dplyr Package in R (20)

Getting Started with MDX 20140625a
Getting Started with MDX 20140625aGetting Started with MDX 20140625a
Getting Started with MDX 20140625a
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 
Data mining 3 - Data Models and Data Warehouse Design (cheat sheet - printable)
Data mining  3 - Data Models and Data Warehouse Design (cheat sheet - printable)Data mining  3 - Data Models and Data Warehouse Design (cheat sheet - printable)
Data mining 3 - Data Models and Data Warehouse Design (cheat sheet - printable)
 
Pass 2018 introduction to dax
Pass 2018 introduction to daxPass 2018 introduction to dax
Pass 2018 introduction to dax
 
Advanced excel unit 01
Advanced excel unit 01Advanced excel unit 01
Advanced excel unit 01
 
Adding measures to Calcite SQL
Adding measures to Calcite SQLAdding measures to Calcite SQL
Adding measures to Calcite SQL
 
Chris Seebacher Portfolio
Chris Seebacher PortfolioChris Seebacher Portfolio
Chris Seebacher Portfolio
 
Ali upload
Ali uploadAli upload
Ali upload
 
Introduction - Using Stata
Introduction - Using StataIntroduction - Using Stata
Introduction - Using Stata
 
Oracle sql analytic functions
Oracle sql analytic functionsOracle sql analytic functions
Oracle sql analytic functions
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
CS 151 Standard deviation lecture
CS 151 Standard deviation lectureCS 151 Standard deviation lecture
CS 151 Standard deviation lecture
 
Company segmentation - an approach with R
Company segmentation - an approach with RCompany segmentation - an approach with R
Company segmentation - an approach with R
 
Calculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdfCalculation Groups - color 1 slide per page.pdf
Calculation Groups - color 1 slide per page.pdf
 
4. chapter iv(transform)
4. chapter iv(transform)4. chapter iv(transform)
4. chapter iv(transform)
 
Introduction
IntroductionIntroduction
Introduction
 
IT301-Datawarehousing (1) and its sub topics.pptx
IT301-Datawarehousing (1) and its sub topics.pptxIT301-Datawarehousing (1) and its sub topics.pptx
IT301-Datawarehousing (1) and its sub topics.pptx
 
Advanced SQL For Data Scientists
Advanced SQL For Data ScientistsAdvanced SQL For Data Scientists
Advanced SQL For Data Scientists
 
Star schema
Star schemaStar schema
Star schema
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
 

Recently uploaded

Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Pooja Nehwal
 
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...gajnagarg
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...Elaine Werffeli
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...gajnagarg
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...amitlee9823
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...amitlee9823
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachBoston Institute of Analytics
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...karishmasinghjnh
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNKTimothy Spann
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...amitlee9823
 

Recently uploaded (20)

Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...
Just Call Vip call girls Bellary Escorts ☎️9352988975 Two shot with one girl ...
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning Approach
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Nandini Layout ☎ 7737669865 🥵 Book Your One night Stand
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
 

dplyr Package in R

  • 2. Introduction Helps transform and manipulate data Powerful tool to summarise data sets Install: install.packages(dplyr) Activate: library(dplyr)
  • 4. ▪ select ▪ filter ▪ arrange ▪ distinct ▪ mutate ▪ transmute ▪ group_by ▪ summarise ▪ pipe operator (%>%) ▪ slice ▪ count Functions in dplyr
  • 5. • Keeps only those variables (columns) that you want to retain/extract. • Syntax: select(dataset,[column1],[column2],…) Examples:  Select columns Month, Dealer, Item, Quantity: select(sales,Month,Dealer,Item,Qty)  Select columns from Month to Quantity: select(sales,Month:Qty)  Deselect column Month from the dataset: select(sales,-Month)  Select columns ending with the letter “r”: select(sales,ends_with("r"))  Select columns containing the letter “r”: select(sales,contains("r"))  Select columns starting the series “m”: select(sales,matches("m."))  Select columns with multiple variables: select(sales,one_of(c("Month","Dealer")))  Select columns starting with the letter “d”: select(sales,starts_with("d")) select()
  • 6. • Keeps only those records (rows) that you want to retain/extract. • Syntax: filter(dataset,criteria) Examples:  Item is Pen: filter(sales,Item==“Pen”)  Quantity is more than 50: filter(sales,Qty>50)  Item is Pencil and Quantity is more than 50: filter(sales,Item=="Pencil"&Qty>50)  Quantity is between 50 and 80: filter(sales,Qty>50&Qty<80)  Item is Pencil or Quantity is more than 50: filter(sales,Item=="Pencil"|Qty>50) filter()
  • 7. Examples:  We want to extract the Sales Manager, Item and Quantity but only for Pencil: i) k=select(sales,SalesManager,Item,Qty) filter(k,Item=="Pencil") ii) select(filter(sales,Item=="Pencil"),SalesManager,Item,Qty) iii) filter(select(sales,SalesManager,Item,Qty),Item=="Pencil")  We want to extract for the Month of May, Dealer, Item and Quantity: i) filter(select(sales,Dealer,Item,Qty),sales$Month=="May") ii) filter(select(sales,Dealer,Item,Qty),Month=="May") select() and filter()
  • 8. • Orders or sorts the records (rows) based on the variable(s). • By default the arrangement is in ascending order. • Syntax: arrange(dataset,column1,[column2],…) Examples:  Sort the dataset based on Months: arrange(sales,Month)  Sort the dataset based on Months and Dealer: arrange(sales,Month,Dealer)  Arrange the data in descending order of Quantity: arrange(sales,desc(Qty)) arrange()
  • 9. • Helps extract unique values from a variable. • Syntax: distinct(dataset,by=column1) Examples:  Find the names of the Dealers: distinct(sales,Dealer)  Find the items sold by each Dealer: arrange(distinct(sales,Dealer,Item),by=Dealer) distinct()
  • 10. • Adds a new variable (column) to the existing dataset • Syntax: mutate(dataset,newcolumn=criteria) Example:  Add a new column Target where it is twice of Quantity: mutate(sales,Target=Qty*2) mutate()
  • 11. • Creates a new variable (column) but drops the existing ones • Syntax: transmute(dataset,newcolumn=criteria) Example:  Create a new column Target where it is twice of Quantity: transmute(sales,tgt=2*Qty) transmute()
  • 12. • Helps create groups in a dataset based on a varaible. • Useful when nested with other functions. • Syntax: group_by(dataset,column1,[column2]…) • Ungroup Syntax: ungroup(dataset) Example:  Create groups in the data based on Items: group_by(sales,Item)  Get the maximum units sold for each item: filter(group_by(sales,by=Item),Qty==max(Qty)) group_by()
  • 13. • Helps generate a single number/statistic for the dataset • Syntax: summarise(dataset,newvariable=function….) Examples:  Total number of units sold across all Items: summarise(sales,total=sum(Qty))  Total number of units sold and total amount: summarise(sales,t_Qty=sum(Qty),t_Amount=sum(Amount))  Total number of records in the dataset: summarise(sales,rowscount=n())  Get the total number of records, quantity sold and amount for each item: summarise(group_by(sales,Item),rcount=n(),untiyqty=sum(Qty),totalamount=sum(Amount))  Every statistic for each dealer and their respective items: summarise(group_by(sales,Dealer,Item),rcount=n(),untiyqty=sum(Qty),totalamount=sum(Amount)) summarise()
  • 14.  We want to extract the top 6 records for Dealers who have sold the Item Pen only: filter((sales,Item=="Pen") select(filter(sales,Item=="Pen"),Item,Dealer,Qty) arrange(select(filter(sales,Item=="Pen"),Item,Dealer,Qty),by=Dealer) head(arrange(select(filter(sales,Item=="Pen"),Item,Dealer,Qty),by=Dealer))  We want the maximum quantity of every item for the month of May with just Dealer, Item and Quantity variables: select(sales,Dealer,Item,Qty) filter(select(sales,Dealer,Item,Qty),sales$Month=="May") group_by(filter(select(sales,Dealer,Item,Qty),sales$Month=="May"),Item,Dealer) summarise(group_by(filter(select(sales,Dealer,Item,Qty),sales$Month=="May"),Item,Dealer),max(Qty)) Assignment
  • 15. • Belongs to magrittr Package. • Helps structure sequence of operations in a single code from left to right. • Helps avoid nesting of funtions. • Operator: %>% Examples:  We want to extract the top 6 records for Dealers who have sold the Item Pen only: sales%>%filter(Item=="Pen")%>%select(Dealer,Item,Qty)%>%arrange(Dealer)%>%head  We want the maximum quantity of every item for the month of May with just Dealer, Item and Quantity variables: sales%>%select(Dealer,Item,Qty)%>%filter(sales$Month=="May")%>%group_by(Item,Dealer)%>%sum marise(max(Qty)) pipe operator %>%
  • 16. • Helps extract records (rows) based on their position. • Syntax: slice(dataset,row numbers) Examples:  Select first ten rows: slice(sales,1:10)  Select rows fifteen to twenty: slice(sales,15:20) slice()
  • 17. • Helps count the number of times a values has appeared in a variable. • Syntax: count(dataset, [column1],[column2],…) Examples:  Count the number of times each Dealer has appeared: count(sales,Dealer)  Count the number of times Pen has appeared: count(sales,Item=="Pen") count()
  • 18. Thanks! Any questions? You can find me at ▪ cc@wkvedu.com