SlideShare una empresa de Scribd logo
1 de 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."

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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

Destacado (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 a 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 a 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
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
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)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

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