SlideShare a Scribd company logo
1 of 15
DPLYR..
WELCOMETO WORLDOF DPLYR...
WHY DPLYR??
 Powerful r package to transform and summarise tabular data in r
programming
 Very fast – Created with execution times in mind
 Easy for those migrating from the SQL world
 When written well, your code reads like a ‘recipe’
 “Code the way you think”
Howdo Iget dplyr?
To install dplyr
install.packages("dplyr")
To load dplyr
library(dplyr)
Important dplyr verbs to remember
select
 Selecting columns using select()
 Select a set of columns: the name and the sleep_total columns.
sleepData <- select(msleep, name, sleep_total) head(sleepData)
 To select all the columns except a specific column, use the “-“
(subtraction) operator (also known as negative indexing)
 head(select(msleep, -name))
 To select a range of columns by name, use the “:” (colon) operator
 head(select(msleep, name:order))
 To select all columns that start with the character string “sl”, use
the function starts_with()
 head(select(msleep, starts_with("sl")))
Some additional options to select
columns based on a specific criteria
include......
 ends_with() = Select columns that end
with a character string
 contains() = Select columns that contain a
character string
 matches() = Select columns that match a
regular expression
 one_of() = Select columns names that are
from a group of names
filter
 Filter the rows for mammals that sleep a total of more than 16
hours and have a body weight of greater than 1 kilogram.
filter(msleep, sleep_total >= 16, bodywt >= 1)
 Usage:
 Returns a subset of rows
 Multiple conditions can be supplied.
 They are combined with an AND
filter(data, condition)
Arrange or re-order rows
 Usage:
– Returns a reordered set of rows
– Multiple inputs are arranged from left-to-right
Ex:
 To arrange (or re-order) rows by a particular column such as the
taxonomic order, list the name of the column you want to arrange
the rows by
msleep %>% arrange(order) %>% head
 Something slightly more complicated: same as above, except
arrange the rows in the sleep_total column in a descending order.
For this, use the function desc()
arrange(data, column_to_sort_by)
mutate
 The mutate() function will add new columns to the data
frame.
 Create a new column called rem_proportion which is the
ratio of rem sleep to total amount of sleep.
msleep %>% mutate(rem_proportion = sleep_rem / sleep_total) %>% head
mutate(data, new_col =
func(oldcolumns)
Summarise
 The summarise() function will create summary statistics for a
given column in the data frame such as finding the mean.
 For example, to compute the average number of hours of sleep,
apply the mean() function to the column sleep_total and call the
summary value avg_sleep.
msleep %>% summarise(avg_sleep = mean(sleep_total))
 There are many other summary statistics you could consider
such sd(), min(), max(), median(), sum(), n()(returns the length of
vector), first() (returns first value in vector), last() (returns last value
in vector) and n_distinct() (number of distinct values in vector).
GROUP BY..
 The group_by() verb is an important function in dplyr.
 It’s related to concept of “split-apply-combine”. We literally
want to split the data frame by some variable (e.g. taxonomic
order), apply a function to the individual data frames and
then combine the output.
 Group_by creates groups of data
 Summarize aggregates the data for each group
msleep %>% group_by(order) %>% summarise(avg_sleep =
mean(sleep_total), min_sleep = min(sleep_total), max_sleep =
max(sleep_total), total = n())
SELECT,FILTER,MUTATE, ARRANGE,SUMMARIZE ANDGROUPBY
PIPE OPERATOR%>%
 Dplyr imports this operator from another package (magrittr). This
operator allows you to pipe the output from one function to the
input of another function. Instead of nesting functions (reading
from the inside to the outside), the idea of of piping is to read the
functions from left to right.
 The output of a series of “pipes” can also be fed to a “plot”
command
 Here’s an example you have seen:
msleep %>% select(name, sleep_total) %>%
Refernces..
 Slideshare.com
 Stackoverflow.com
Bimba santosh pawar
Thankyou..

More Related Content

What's hot (20)

MySQL Basics
MySQL BasicsMySQL Basics
MySQL Basics
 
Window functions in MySQL 8.0
Window functions in MySQL 8.0Window functions in MySQL 8.0
Window functions in MySQL 8.0
 
Sql commands
Sql commandsSql commands
Sql commands
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Python set
Python setPython set
Python set
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 
Array
ArrayArray
Array
 
Sql ppt
Sql pptSql ppt
Sql ppt
 
Descriptive Statistics with R
Descriptive Statistics with RDescriptive Statistics with R
Descriptive Statistics with R
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Slowly changing dimension
Slowly changing dimension Slowly changing dimension
Slowly changing dimension
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
ER MODEL
ER MODELER MODEL
ER MODEL
 
pandas: Powerful data analysis tools for Python
pandas: Powerful data analysis tools for Pythonpandas: Powerful data analysis tools for Python
pandas: Powerful data analysis tools for Python
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
 

Similar to DPLYR package in R

Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functionsNitesh Singh
 
Stata Programming Cheat Sheet
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat SheetLaura Hughes
 
Summerization notes for descriptive statistics using r
Summerization notes for descriptive statistics using r Summerization notes for descriptive statistics using r
Summerization notes for descriptive statistics using r Ashwini Mathur
 
maXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VIImaXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VIIMax Kleiner
 
Stata cheatsheet programming
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programmingTim Essam
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply FunctionSakthi Dasans
 
BITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQLBITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQLBITS
 
Introduction Oracle Database 11g Release 2 for developers
Introduction Oracle Database 11g Release 2 for developersIntroduction Oracle Database 11g Release 2 for developers
Introduction Oracle Database 11g Release 2 for developersLucas Jellema
 
Data Wrangling with dplyr and tidyr Cheat Sheet
Data Wrangling with dplyr and tidyr Cheat SheetData Wrangling with dplyr and tidyr Cheat Sheet
Data Wrangling with dplyr and tidyr Cheat SheetDr. Volkan OBAN
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Barry DeCicco
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureRai University
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functionsVivek Singh
 
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdfTerrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdffeetshoemart
 

Similar to DPLYR package in R (20)

Data transformation-cheatsheet
Data transformation-cheatsheetData transformation-cheatsheet
Data transformation-cheatsheet
 
Introduction to oracle functions
Introduction to oracle functionsIntroduction to oracle functions
Introduction to oracle functions
 
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek SharmaIntroduction to Oracle Functions--(SQL)--Abhishek Sharma
Introduction to Oracle Functions--(SQL)--Abhishek Sharma
 
Stata Programming Cheat Sheet
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat Sheet
 
Summerization notes for descriptive statistics using r
Summerization notes for descriptive statistics using r Summerization notes for descriptive statistics using r
Summerization notes for descriptive statistics using r
 
maXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VIImaXbox starter69 Machine Learning VII
maXbox starter69 Machine Learning VII
 
Stata cheatsheet programming
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programming
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function
 
BITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQLBITS: Introduction to relational databases and MySQL - SQL
BITS: Introduction to relational databases and MySQL - SQL
 
R for Statistical Computing
R for Statistical ComputingR for Statistical Computing
R for Statistical Computing
 
Neural networks using tensor flow in amazon deep learning server
Neural networks using tensor flow in amazon deep learning serverNeural networks using tensor flow in amazon deep learning server
Neural networks using tensor flow in amazon deep learning server
 
Introduction Oracle Database 11g Release 2 for developers
Introduction Oracle Database 11g Release 2 for developersIntroduction Oracle Database 11g Release 2 for developers
Introduction Oracle Database 11g Release 2 for developers
 
Data Wrangling with dplyr and tidyr Cheat Sheet
Data Wrangling with dplyr and tidyr Cheat SheetData Wrangling with dplyr and tidyr Cheat Sheet
Data Wrangling with dplyr and tidyr Cheat Sheet
 
Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06Introduction to r studio on aws 2020 05_06
Introduction to r studio on aws 2020 05_06
 
Bsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structureBsc cs ii dfs u-1 introduction to data structure
Bsc cs ii dfs u-1 introduction to data structure
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functions
 
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdfTerrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
Terrain AnalysisBackgroundAircraft frequently rely on terrain el.pdf
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Mysql
MysqlMysql
Mysql
 
Mysql
MysqlMysql
Mysql
 

Recently uploaded

vip Sarai Rohilla Call Girls 9999965857 Call or WhatsApp Now Book
vip Sarai Rohilla Call Girls 9999965857 Call or WhatsApp Now Bookvip Sarai Rohilla Call Girls 9999965857 Call or WhatsApp Now Book
vip Sarai Rohilla Call Girls 9999965857 Call or WhatsApp Now Bookmanojkuma9823
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理e4aez8ss
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一F La
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 

Recently uploaded (20)

vip Sarai Rohilla Call Girls 9999965857 Call or WhatsApp Now Book
vip Sarai Rohilla Call Girls 9999965857 Call or WhatsApp Now Bookvip Sarai Rohilla Call Girls 9999965857 Call or WhatsApp Now Book
vip Sarai Rohilla Call Girls 9999965857 Call or WhatsApp Now Book
 
Call Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort ServiceCall Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort Service
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
科罗拉多大学波尔得分校毕业证学位证成绩单-可办理
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 

DPLYR package in R

  • 2. WHY DPLYR??  Powerful r package to transform and summarise tabular data in r programming  Very fast – Created with execution times in mind  Easy for those migrating from the SQL world  When written well, your code reads like a ‘recipe’  “Code the way you think”
  • 3. Howdo Iget dplyr? To install dplyr install.packages("dplyr") To load dplyr library(dplyr)
  • 4. Important dplyr verbs to remember
  • 5. select  Selecting columns using select()  Select a set of columns: the name and the sleep_total columns. sleepData <- select(msleep, name, sleep_total) head(sleepData)  To select all the columns except a specific column, use the “-“ (subtraction) operator (also known as negative indexing)  head(select(msleep, -name))  To select a range of columns by name, use the “:” (colon) operator  head(select(msleep, name:order))  To select all columns that start with the character string “sl”, use the function starts_with()  head(select(msleep, starts_with("sl")))
  • 6. Some additional options to select columns based on a specific criteria include......  ends_with() = Select columns that end with a character string  contains() = Select columns that contain a character string  matches() = Select columns that match a regular expression  one_of() = Select columns names that are from a group of names
  • 7. filter  Filter the rows for mammals that sleep a total of more than 16 hours and have a body weight of greater than 1 kilogram. filter(msleep, sleep_total >= 16, bodywt >= 1)  Usage:  Returns a subset of rows  Multiple conditions can be supplied.  They are combined with an AND filter(data, condition)
  • 8. Arrange or re-order rows  Usage: – Returns a reordered set of rows – Multiple inputs are arranged from left-to-right Ex:  To arrange (or re-order) rows by a particular column such as the taxonomic order, list the name of the column you want to arrange the rows by msleep %>% arrange(order) %>% head  Something slightly more complicated: same as above, except arrange the rows in the sleep_total column in a descending order. For this, use the function desc() arrange(data, column_to_sort_by)
  • 9. mutate  The mutate() function will add new columns to the data frame.  Create a new column called rem_proportion which is the ratio of rem sleep to total amount of sleep. msleep %>% mutate(rem_proportion = sleep_rem / sleep_total) %>% head mutate(data, new_col = func(oldcolumns)
  • 10. Summarise  The summarise() function will create summary statistics for a given column in the data frame such as finding the mean.  For example, to compute the average number of hours of sleep, apply the mean() function to the column sleep_total and call the summary value avg_sleep. msleep %>% summarise(avg_sleep = mean(sleep_total))  There are many other summary statistics you could consider such sd(), min(), max(), median(), sum(), n()(returns the length of vector), first() (returns first value in vector), last() (returns last value in vector) and n_distinct() (number of distinct values in vector).
  • 11. GROUP BY..  The group_by() verb is an important function in dplyr.  It’s related to concept of “split-apply-combine”. We literally want to split the data frame by some variable (e.g. taxonomic order), apply a function to the individual data frames and then combine the output.  Group_by creates groups of data  Summarize aggregates the data for each group msleep %>% group_by(order) %>% summarise(avg_sleep = mean(sleep_total), min_sleep = min(sleep_total), max_sleep = max(sleep_total), total = n())
  • 13. PIPE OPERATOR%>%  Dplyr imports this operator from another package (magrittr). This operator allows you to pipe the output from one function to the input of another function. Instead of nesting functions (reading from the inside to the outside), the idea of of piping is to read the functions from left to right.  The output of a series of “pipes” can also be fed to a “plot” command  Here’s an example you have seen: msleep %>% select(name, sleep_total) %>%