SlideShare a Scribd company logo
1 of 9
Apply functions The Dataminingtools.net Team
Apply functions Apply functions are used to execute a function repetitively. "Apply" functions keeps us from having to write loops to perform some operation on every row or every column of a matrix or data frame, or on every element in a list.
Apply family sapply() lapply() apply() ,[object Object]
tapply()
rapply(),[object Object]
Usage Using ‘apply’ > apply (state.x77, 2, median) Population     Income Illiteracy   Life Exp     Murder    2838.500   4519.000      0.950     70.675      6.850     HS Grad      Frost       Area      53.250    114.500  54277.000 The 2 means "go by column" -- a 1 would have meant "go by row."
Usage We construct a function and pass it to apply. It computes the median and maximum of each column of state.x77.
Usage  apply() works on each row, one at a time, to find the smallest number in each row. which() function, returns the indices within a vector for which the vector holds the value TRUE
lapplyand sapply The lapply() function works on any list. The "l" in "lapply" stands for "list." The "s" in "sapply" stands for "simplify."

More Related Content

What's hot

Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
Tech_MX
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
Saqib Saeed
 
Stack linked list
Stack linked listStack linked list
Stack linked list
bhargav0077
 

What's hot (17)

String predefined functions in C programming
String predefined functions in C  programmingString predefined functions in C  programming
String predefined functions in C programming
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
BB - Functions (Operations and Piecewise)
BB  - Functions (Operations and Piecewise)BB  - Functions (Operations and Piecewise)
BB - Functions (Operations and Piecewise)
 
MCM FUNCTIONS BLACKBOARD COMPATIBILITY
MCM FUNCTIONS BLACKBOARD COMPATIBILITYMCM FUNCTIONS BLACKBOARD COMPATIBILITY
MCM FUNCTIONS BLACKBOARD COMPATIBILITY
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
CS106 Lab 11 - Functions (passing by reference)
CS106 Lab 11 - Functions (passing by reference)CS106 Lab 11 - Functions (passing by reference)
CS106 Lab 11 - Functions (passing by reference)
 
Queue
QueueQueue
Queue
 
Ch06 Stack
Ch06  StackCh06  Stack
Ch06 Stack
 
Stack and heap
Stack and heapStack and heap
Stack and heap
 
Functional Programming in Go
Functional Programming in GoFunctional Programming in Go
Functional Programming in Go
 
Lecture8
Lecture8Lecture8
Lecture8
 
Data Structure (Stack)
Data Structure (Stack)Data Structure (Stack)
Data Structure (Stack)
 
Sync with async
Sync with  asyncSync with  async
Sync with async
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 

Viewers also liked

Vanhempainillan satoa 2011 nettiversio
Vanhempainillan satoa 2011 nettiversioVanhempainillan satoa 2011 nettiversio
Vanhempainillan satoa 2011 nettiversio
santramari
 

Viewers also liked (20)

R Environment
R EnvironmentR Environment
R Environment
 
R Statistics
R StatisticsR Statistics
R Statistics
 
R Graphics
R GraphicsR Graphics
R Graphics
 
Vanhempainillan satoa 2011 nettiversio
Vanhempainillan satoa 2011 nettiversioVanhempainillan satoa 2011 nettiversio
Vanhempainillan satoa 2011 nettiversio
 
Kamal Adeni - Emerging Role Of Tax Technologist In A ERP Environment
Kamal Adeni  -  Emerging Role Of Tax Technologist In A  ERP EnvironmentKamal Adeni  -  Emerging Role Of Tax Technologist In A  ERP Environment
Kamal Adeni - Emerging Role Of Tax Technologist In A ERP Environment
 
Kamal Adeni - Nuts and Bolts Of Sales Tax
Kamal Adeni - Nuts and Bolts Of  Sales TaxKamal Adeni - Nuts and Bolts Of  Sales Tax
Kamal Adeni - Nuts and Bolts Of Sales Tax
 
Kamal Adeni - Taxability Of Freight Charges In Supply Chain Management
Kamal Adeni - Taxability Of Freight Charges In Supply Chain ManagementKamal Adeni - Taxability Of Freight Charges In Supply Chain Management
Kamal Adeni - Taxability Of Freight Charges In Supply Chain Management
 
Resume Kamal Adeni
Resume Kamal Adeni Resume Kamal Adeni
Resume Kamal Adeni
 
Advanced R Graphics
Advanced R GraphicsAdvanced R Graphics
Advanced R Graphics
 
R Functions
R FunctionsR Functions
R Functions
 
R Datatypes
R DatatypesR Datatypes
R Datatypes
 
Introduction To R
Introduction To RIntroduction To R
Introduction To R
 
W:\Scott & Baldwin\Marketing\Business Leadership Seminars\September 2008\...
W:\Scott & Baldwin\Marketing\Business Leadership Seminars\September 2008\...W:\Scott & Baldwin\Marketing\Business Leadership Seminars\September 2008\...
W:\Scott & Baldwin\Marketing\Business Leadership Seminars\September 2008\...
 
Chris Sharman-SPEDDEXES 2014
Chris Sharman-SPEDDEXES 2014Chris Sharman-SPEDDEXES 2014
Chris Sharman-SPEDDEXES 2014
 
What Are Common Forecasting Techniques
What Are Common Forecasting Techniques What Are Common Forecasting Techniques
What Are Common Forecasting Techniques
 
Interieurfotografie Alken Maes Voor Steelcase
Interieurfotografie Alken Maes Voor SteelcaseInterieurfotografie Alken Maes Voor Steelcase
Interieurfotografie Alken Maes Voor Steelcase
 
Interieur Fotografie Valerie Clarysse Voor Donum
Interieur Fotografie Valerie Clarysse Voor DonumInterieur Fotografie Valerie Clarysse Voor Donum
Interieur Fotografie Valerie Clarysse Voor Donum
 
Kamal Adeni - VAT Federal Deficit Buster ?
Kamal Adeni - VAT  Federal Deficit Buster ?Kamal Adeni - VAT  Federal Deficit Buster ?
Kamal Adeni - VAT Federal Deficit Buster ?
 
Integral Fusion
Integral FusionIntegral Fusion
Integral Fusion
 
Industriële fotografie voor Bekina
Industriële fotografie voor BekinaIndustriële fotografie voor Bekina
Industriële fotografie voor Bekina
 

Similar to Apply Functions in R

ObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docxObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docx
vannagoforth
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
dunhamadell
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
festockton
 

Similar to Apply Functions in R (20)

Jquery 1
Jquery 1Jquery 1
Jquery 1
 
ObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docxObjectivesMore practice with recursion.Practice writing some tem.docx
ObjectivesMore practice with recursion.Practice writing some tem.docx
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
Google collections api an introduction
Google collections api   an introductionGoogle collections api   an introduction
Google collections api an introduction
 
Synapse india complain sharing info on chapter 8 operator overloading
Synapse india complain sharing info on chapter 8   operator overloadingSynapse india complain sharing info on chapter 8   operator overloading
Synapse india complain sharing info on chapter 8 operator overloading
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
 
4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function4 R Tutorial DPLYR Apply Function
4 R Tutorial DPLYR Apply Function
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
Unit 7 Java
Unit 7 JavaUnit 7 Java
Unit 7 Java
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0C++11 - A Change in Style - v2.0
C++11 - A Change in Style - v2.0
 
Operators in java
Operators in javaOperators in java
Operators in java
 
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신Beyond Java: 자바 8을 중심으로 본 자바의 혁신
Beyond Java: 자바 8을 중심으로 본 자바의 혁신
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
 
Matlab Manual
Matlab ManualMatlab Manual
Matlab Manual
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

Apply Functions in R

  • 1. Apply functions The Dataminingtools.net Team
  • 2. Apply functions Apply functions are used to execute a function repetitively. "Apply" functions keeps us from having to write loops to perform some operation on every row or every column of a matrix or data frame, or on every element in a list.
  • 3.
  • 5.
  • 6. Usage Using ‘apply’ > apply (state.x77, 2, median) Population Income Illiteracy Life Exp Murder 2838.500 4519.000 0.950 70.675 6.850 HS Grad Frost Area 53.250 114.500 54277.000 The 2 means "go by column" -- a 1 would have meant "go by row."
  • 7. Usage We construct a function and pass it to apply. It computes the median and maximum of each column of state.x77.
  • 8. Usage  apply() works on each row, one at a time, to find the smallest number in each row. which() function, returns the indices within a vector for which the vector holds the value TRUE
  • 9. lapplyand sapply The lapply() function works on any list. The "l" in "lapply" stands for "list." The "s" in "sapply" stands for "simplify."
  • 10. tapply tapply() is a very powerful function that lets us break a vector into pieces and apply some function to each of the pieces. It is like sapply(), except that with sapply() the pieces are always elements of a list. With tapply() we get to specify how the breakdown is done. >tapply(barley$yield, barley$site, mean) Grand Rapids Duluth University Farm Morris Crookston Waseca 24.93167 27.99667 32.66667 35.4 37.42 48.10833