SlideShare a Scribd company logo
Split-Apply-Combine Strategy with the Package plyr

Hadley Wickham. The split-apply-combine strategy for data
 analysis. Journal of Statistical Software, 40(1):1–29, 2011.
           URL http://www.jstatsoft.org/v40/i01/.

                   http://plyr.had.co.nz/
Common action in statistical analyses:
• Split up a dataset into pieces
• Apply a function to these pieces
• Combine output and examine the results

Examples:
• Calculate the mean of response by treatment
• Run ANOVA on numerous response variables
• Calculate total precipitation from weather data by
  month or year
plyr offers:
• a streamlined, simplified, and unified framework and
   alterative to the R ‘apply’ base functions (apply, sapply, tapply,
   lapply, mapply, etc.)
• a streamlined and simplified approach to writing for loops

When not to use plyr:
• each iteration requires overlapping data (e.g., running mean)
• each iteration depends on the previous iteration (e.g.,
  dynamic simulation)
The package plyr uses a similar command **ply
• where the 1st ‘*’ designates the input type
• 2nd ‘*’ designates the output type.

The choices for the ‘*’ are either, ‘a’, ‘d’, ‘l’, or ’_’
• a = array
• d = data frame
• l = list
• _ means the output is discarded

• Examples:
   – ddply = input is a dataframe, output is a data frame
   – alply = input is an array, output is a list
• Full function: ddply(.data, .variables, .fun, ..., )

• .data = R object that will be split up, processed and
  recombined
• .variables (.margins for arrays) = describes how to split up the
  input into pieces
• .fun, = the processing function, and is applied to each piece in
  turn.
• All further arguments are passed on to the processing
  function.
• If you omit .fun the individual pieces will not be modified, but
  the entire data structure will be converted from one type to
  another.
The package plyr uses a similar command style: **ply
• where the 1st ‘*’ designates the input type
• 2nd ‘*’ designates the output type.

The choices for the ‘*’ are either, ‘a’, ‘d’, ‘l’, or ’_’
• a = array
• d = data frame
• l = list
• _ = the output is discarded

• Examples:
   – ddply = input is a data frame, output is a data frame
   – alply = input is an array, output is a list

More Related Content

What's hot

Data structure and algorithm All in One
Data structure and algorithm All in OneData structure and algorithm All in One
Data structure and algorithm All in One
jehan1987
 
Query trees
Query treesQuery trees
Query trees
Shefa Idrees
 
Introduction of data structure
Introduction of data structureIntroduction of data structure
Introduction of data structureeShikshak
 
Lecture 1 and 2
Lecture 1 and 2Lecture 1 and 2
Lecture 1 and 2
SaheedTundeZubairSTA
 
Basic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - NotesBasic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - Notes
Omprakash Chauhan
 
Whats new in Process Simulator 2016 sp1?
Whats new in Process Simulator 2016 sp1?Whats new in Process Simulator 2016 sp1?
Whats new in Process Simulator 2016 sp1?
ProModel Corporation
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
Kuber Chandra
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Hoang Nguyen
 
ProModel MedModel 2016 sp1 What's New?
ProModel MedModel 2016 sp1 What's New?ProModel MedModel 2016 sp1 What's New?
ProModel MedModel 2016 sp1 What's New?
ProModel Corporation
 
Sorting
SortingSorting
Queues
QueuesQueues
Data Structures 01
Data Structures 01Data Structures 01
Data Structures 01
Budditha Hettige
 
Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
Narayan Sau
 
ADS Introduction
ADS IntroductionADS Introduction
ADS Introduction
NagendraK18
 
Python advanced 3.the python std lib by example – algorithm
Python advanced 3.the python std lib by example – algorithmPython advanced 3.the python std lib by example – algorithm
Python advanced 3.the python std lib by example – algorithmJohn(Qiang) Zhang
 
Queue
QueueQueue
Python advanced 3.the python std lib by example –data structures
Python advanced 3.the python std lib by example –data structuresPython advanced 3.the python std lib by example –data structures
Python advanced 3.the python std lib by example –data structuresJohn(Qiang) Zhang
 
Cost estimation for Query Optimization
Cost estimation for Query OptimizationCost estimation for Query Optimization
Cost estimation for Query Optimization
Ravinder Kamboj
 

What's hot (20)

Stack and Heap
Stack and HeapStack and Heap
Stack and Heap
 
Data structure and algorithm All in One
Data structure and algorithm All in OneData structure and algorithm All in One
Data structure and algorithm All in One
 
Query trees
Query treesQuery trees
Query trees
 
Introduction of data structure
Introduction of data structureIntroduction of data structure
Introduction of data structure
 
Lecture 1 and 2
Lecture 1 and 2Lecture 1 and 2
Lecture 1 and 2
 
Basic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - NotesBasic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - Notes
 
Whats new in Process Simulator 2016 sp1?
Whats new in Process Simulator 2016 sp1?Whats new in Process Simulator 2016 sp1?
Whats new in Process Simulator 2016 sp1?
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Functions with heap and stack
 
ProModel MedModel 2016 sp1 What's New?
ProModel MedModel 2016 sp1 What's New?ProModel MedModel 2016 sp1 What's New?
ProModel MedModel 2016 sp1 What's New?
 
Sorting
SortingSorting
Sorting
 
Queues
QueuesQueues
Queues
 
Data Structures 01
Data Structures 01Data Structures 01
Data Structures 01
 
Data structure and algorithm using java
Data structure and algorithm using javaData structure and algorithm using java
Data structure and algorithm using java
 
ADS Introduction
ADS IntroductionADS Introduction
ADS Introduction
 
Python advanced 3.the python std lib by example – algorithm
Python advanced 3.the python std lib by example – algorithmPython advanced 3.the python std lib by example – algorithm
Python advanced 3.the python std lib by example – algorithm
 
Queue
QueueQueue
Queue
 
Python advanced 3.the python std lib by example –data structures
Python advanced 3.the python std lib by example –data structuresPython advanced 3.the python std lib by example –data structures
Python advanced 3.the python std lib by example –data structures
 
Cost estimation for Query Optimization
Cost estimation for Query OptimizationCost estimation for Query Optimization
Cost estimation for Query Optimization
 

Similar to Intro to plyr for Davis R Users' Group, by Steve Culman

358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
sumitbardhan
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
JohnStuart83
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
Jabs6
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
KarthickT28
 
Mathematical Modeling With Maple
Mathematical Modeling With MapleMathematical Modeling With Maple
Mathematical Modeling With Maple
Vaitheeswaran Gnanaraj
 
Hadoop map reduce concepts
Hadoop map reduce conceptsHadoop map reduce concepts
Hadoop map reduce concepts
Subhas Kumar Ghosh
 
Data Structures 7
Data Structures 7Data Structures 7
Data Structures 7
Dr.Umadevi V
 
Data Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxData Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptx
GIRISHKUMARBC1
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4
DianaGray10
 
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset Preparation
Andrew Ferlitsch
 
Data Structure Introduction for Beginners
Data Structure Introduction for BeginnersData Structure Introduction for Beginners
Data Structure Introduction for Beginners
ramanathan2006
 
DSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfDSJ_Unit I & II.pdf
DSJ_Unit I & II.pdf
Arumugam90
 
Week-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docxWeek-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docx
helzerpatrina
 
Sv data types and sv interface usage in uvm
Sv data types and sv interface usage in uvmSv data types and sv interface usage in uvm
Sv data types and sv interface usage in uvm
HARINATH REDDY
 
DATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxDATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptx
ShivamKrPathak
 
17641.ppt
17641.ppt17641.ppt
17641.ppt
vikassingh569137
 
Slides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MDSlides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MD
SonaCharles2
 
17641.ppt
17641.ppt17641.ppt
Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in Swift
Saugat Gautam
 

Similar to Intro to plyr for Davis R Users' Group, by Steve Culman (20)

358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
 
UNIT 1.pptx
UNIT 1.pptxUNIT 1.pptx
UNIT 1.pptx
 
Data Structures in C
Data Structures in CData Structures in C
Data Structures in C
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
 
U nit i data structure-converted
U nit   i data structure-convertedU nit   i data structure-converted
U nit i data structure-converted
 
Mathematical Modeling With Maple
Mathematical Modeling With MapleMathematical Modeling With Maple
Mathematical Modeling With Maple
 
Hadoop map reduce concepts
Hadoop map reduce conceptsHadoop map reduce concepts
Hadoop map reduce concepts
 
Data Structures 7
Data Structures 7Data Structures 7
Data Structures 7
 
Data Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxData Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptx
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4
 
Machine Learning - Dataset Preparation
Machine Learning - Dataset PreparationMachine Learning - Dataset Preparation
Machine Learning - Dataset Preparation
 
Data Structure Introduction for Beginners
Data Structure Introduction for BeginnersData Structure Introduction for Beginners
Data Structure Introduction for Beginners
 
DSJ_Unit I & II.pdf
DSJ_Unit I & II.pdfDSJ_Unit I & II.pdf
DSJ_Unit I & II.pdf
 
Week-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docxWeek-3 – System RSupplemental material1Recap •.docx
Week-3 – System RSupplemental material1Recap •.docx
 
Sv data types and sv interface usage in uvm
Sv data types and sv interface usage in uvmSv data types and sv interface usage in uvm
Sv data types and sv interface usage in uvm
 
DATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptxDATA STRUCTURES unit 1.pptx
DATA STRUCTURES unit 1.pptx
 
17641.ppt
17641.ppt17641.ppt
17641.ppt
 
Slides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MDSlides on introduction to R by ArinBasu MD
Slides on introduction to R by ArinBasu MD
 
17641.ppt
17641.ppt17641.ppt
17641.ppt
 
Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in Swift
 

More from Noam Ross

An introduction to structural equation models in R using the Lavaan package
An introduction to structural equation models in R using the Lavaan packageAn introduction to structural equation models in R using the Lavaan package
An introduction to structural equation models in R using the Lavaan package
Noam Ross
 
Spatial Analysis with R - the Good, the Bad, and the Pretty
Spatial Analysis with R - the Good, the Bad, and the PrettySpatial Analysis with R - the Good, the Bad, and the Pretty
Spatial Analysis with R - the Good, the Bad, and the Pretty
Noam Ross
 
R and the forest vegetation simulator
R and the forest vegetation simulatorR and the forest vegetation simulator
R and the forest vegetation simulator
Noam Ross
 
Andersen et al. 2004: Stoichiometry and Dynamics
Andersen et al. 2004: Stoichiometry and DynamicsAndersen et al. 2004: Stoichiometry and Dynamics
Andersen et al. 2004: Stoichiometry and Dynamics
Noam Ross
 
General Additive Models in R
General Additive Models in RGeneral Additive Models in R
General Additive Models in R
Noam Ross
 
Agren 2012 - by Brian Smithers
Agren 2012 - by Brian SmithersAgren 2012 - by Brian Smithers
Agren 2012 - by Brian Smithers
Noam Ross
 
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyStoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyNoam Ross
 
Ecological Stoichiometry: The Consumer Connection: Matt Whalen
Ecological Stoichiometry: The Consumer Connection: Matt WhalenEcological Stoichiometry: The Consumer Connection: Matt Whalen
Ecological Stoichiometry: The Consumer Connection: Matt WhalenNoam Ross
 
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyStoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyNoam Ross
 
Marklein CNP stoichiometry
Marklein CNP stoichiometryMarklein CNP stoichiometry
Marklein CNP stoichiometry
Noam Ross
 
Modifying River-Floodplain Systems: A Historical and Ecological Perspective
Modifying River-Floodplain Systems: A Historical and Ecological PerspectiveModifying River-Floodplain Systems: A Historical and Ecological Perspective
Modifying River-Floodplain Systems: A Historical and Ecological Perspective
Noam Ross
 
Emerging Forest Disease
Emerging Forest DiseaseEmerging Forest Disease
Emerging Forest Disease
Noam Ross
 
Baskett Lab Uncertainty lab meeting
Baskett Lab Uncertainty lab meetingBaskett Lab Uncertainty lab meeting
Baskett Lab Uncertainty lab meetingNoam Ross
 

More from Noam Ross (13)

An introduction to structural equation models in R using the Lavaan package
An introduction to structural equation models in R using the Lavaan packageAn introduction to structural equation models in R using the Lavaan package
An introduction to structural equation models in R using the Lavaan package
 
Spatial Analysis with R - the Good, the Bad, and the Pretty
Spatial Analysis with R - the Good, the Bad, and the PrettySpatial Analysis with R - the Good, the Bad, and the Pretty
Spatial Analysis with R - the Good, the Bad, and the Pretty
 
R and the forest vegetation simulator
R and the forest vegetation simulatorR and the forest vegetation simulator
R and the forest vegetation simulator
 
Andersen et al. 2004: Stoichiometry and Dynamics
Andersen et al. 2004: Stoichiometry and DynamicsAndersen et al. 2004: Stoichiometry and Dynamics
Andersen et al. 2004: Stoichiometry and Dynamics
 
General Additive Models in R
General Additive Models in RGeneral Additive Models in R
General Additive Models in R
 
Agren 2012 - by Brian Smithers
Agren 2012 - by Brian SmithersAgren 2012 - by Brian Smithers
Agren 2012 - by Brian Smithers
 
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyStoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
 
Ecological Stoichiometry: The Consumer Connection: Matt Whalen
Ecological Stoichiometry: The Consumer Connection: Matt WhalenEcological Stoichiometry: The Consumer Connection: Matt Whalen
Ecological Stoichiometry: The Consumer Connection: Matt Whalen
 
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew HaggertyStoichiometry of the Microbial Loop: J. Matthew Haggerty
Stoichiometry of the Microbial Loop: J. Matthew Haggerty
 
Marklein CNP stoichiometry
Marklein CNP stoichiometryMarklein CNP stoichiometry
Marklein CNP stoichiometry
 
Modifying River-Floodplain Systems: A Historical and Ecological Perspective
Modifying River-Floodplain Systems: A Historical and Ecological PerspectiveModifying River-Floodplain Systems: A Historical and Ecological Perspective
Modifying River-Floodplain Systems: A Historical and Ecological Perspective
 
Emerging Forest Disease
Emerging Forest DiseaseEmerging Forest Disease
Emerging Forest Disease
 
Baskett Lab Uncertainty lab meeting
Baskett Lab Uncertainty lab meetingBaskett Lab Uncertainty lab meeting
Baskett Lab Uncertainty lab meeting
 

Recently uploaded

Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 

Recently uploaded (20)

Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

Intro to plyr for Davis R Users' Group, by Steve Culman

  • 1. Split-Apply-Combine Strategy with the Package plyr Hadley Wickham. The split-apply-combine strategy for data analysis. Journal of Statistical Software, 40(1):1–29, 2011. URL http://www.jstatsoft.org/v40/i01/. http://plyr.had.co.nz/
  • 2. Common action in statistical analyses: • Split up a dataset into pieces • Apply a function to these pieces • Combine output and examine the results Examples: • Calculate the mean of response by treatment • Run ANOVA on numerous response variables • Calculate total precipitation from weather data by month or year
  • 3. plyr offers: • a streamlined, simplified, and unified framework and alterative to the R ‘apply’ base functions (apply, sapply, tapply, lapply, mapply, etc.) • a streamlined and simplified approach to writing for loops When not to use plyr: • each iteration requires overlapping data (e.g., running mean) • each iteration depends on the previous iteration (e.g., dynamic simulation)
  • 4. The package plyr uses a similar command **ply • where the 1st ‘*’ designates the input type • 2nd ‘*’ designates the output type. The choices for the ‘*’ are either, ‘a’, ‘d’, ‘l’, or ’_’ • a = array • d = data frame • l = list • _ means the output is discarded • Examples: – ddply = input is a dataframe, output is a data frame – alply = input is an array, output is a list
  • 5. • Full function: ddply(.data, .variables, .fun, ..., ) • .data = R object that will be split up, processed and recombined • .variables (.margins for arrays) = describes how to split up the input into pieces • .fun, = the processing function, and is applied to each piece in turn. • All further arguments are passed on to the processing function. • If you omit .fun the individual pieces will not be modified, but the entire data structure will be converted from one type to another.
  • 6. The package plyr uses a similar command style: **ply • where the 1st ‘*’ designates the input type • 2nd ‘*’ designates the output type. The choices for the ‘*’ are either, ‘a’, ‘d’, ‘l’, or ’_’ • a = array • d = data frame • l = list • _ = the output is discarded • Examples: – ddply = input is a data frame, output is a data frame – alply = input is an array, output is a list