SlideShare a Scribd company logo
FUNCTIONS IN R
PROGRAMMING
PRESENTED BY
CHINCHU P
INTRODUCTION
 A function is a set of statements organized together to perform a
specific task.
 R has a large number of in-built functions and the user can create
their own functions.
 In R, a function is an object so the R interpreter is able to pass
control to the function , along with arguments that may be
necessary for the function to accomplish the actions.
FUNCTION DEFINITION
 An R function is created by using the keyword ‘function’.
Syntax:
FUNCTION COMPONENTS
 The different parts of a function are-
Function Name – This is the actual name of the function. It is stored in
R environment as an object with this name.
Arguments – An argument is a placeholder. When a function is
invoked ,you pass a value to the argument. Arguments
are optional; that is, a function may contain no
arguments. Also arguments can have default values.
Continued:-
Function Body – The function body contains a collection of -
statements that defines what the function does.
Return Value – The return value of a function is the last expression in
the function body to be evaluated.
BUILT-IN FUNCTION
 R has many in-built functions which can be directly called in the program without
defining them first.
 Simple examples of in-built functions are seq(),mean(),max(),sum() and paste() etc.
 They are directly called by user written programs.
Continued:-
Example :
USER-DEFINED FUNCTION
 User defined functions are specific to what a user wants.
 Once its created they can be used like the built-in functions.
Example:-
CALLING A FUNCTION
 It is nothing but calling the original function with a valid number of arguments.
 A function can be called with an argument ,without an argument and with a
default value as well.
 The arguments to a function call can be supplied in the same sequence as defined
in the function or they can be supplied in a different sequence but assigned to the
names of the arguments.
 We can define the value of the arguments in the function definition and call the
function without supplying any argument to get the default result . we can also
call such functions by supplying new values of the argument and get non default
result.
Continued:-
1. Calling a function
Output:
Continued:-
2. Calling a function without an argument
Output:
Continued:-
3. Calling a function with argument values(by position and by name)
Output:
Continued:-
4. Calling a function with Default argument
Output:
Lazy Evaluation of function
 Arguments to functions are evaluated lazily, which means so they are evaluated
only when needed by the function body.
RECURSIVE FUNCTIONS
 It is a type of looping technique.
 It exploits the basic working of function in R.
 Recursion is when the function calls itself.
 This forms a loop, where every time the function is called , it calls itself again and
again and this technique is known as recursion.
 Recursive functions call themselves. They break down the problem into smaller
components. The function() calls itself within the original function()
each of the smaller components. After this, the results will be put together
to solve the original problem.
Continued:-
 Key features
 The use of recursion, often, makes the code shorter and it looks cleans.
 It is a simple solution for a few cases.
 It expresses in a function that calls itself.
 Applications
 Recursive functions are used in many efficient programming techniques like dynamic
programming language(DSL) or divide and conquer algorithms.
 In dynamic programming, for both top-down as well as bottom-up approaches ,
recursion is vital for performance.
Continued:-
Example:
rec_fac(5)
KEY POINTS TO REMEMBER
1. What is a Function
2. Definition
3. Syntax
4. Function components
5. Built-in function
6. User-defined function
7. Function call
8. Recursive Function
9. Examples
TASK
1.Create a function for rectangle , calculate the area and print the result.
2.Create a function to check whether the given number is odd or even.
THANK YOU
Ad

More Related Content

What's hot (20)

Compiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent OptimizationsCompiler Design- Machine Independent Optimizations
Compiler Design- Machine Independent Optimizations
Jyothishmathi Institute of Technology and Science Karimnagar
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
Huawei Technologies
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Yacc
YaccYacc
Yacc
BBDITM LUCKNOW
 
Data types in python
Data types in pythonData types in python
Data types in python
RaginiJain21
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
Compilers
CompilersCompilers
Compilers
Bense Tony
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
nadarmispapaulraj
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
Gaditek
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
Hemant Sharma
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro calls
SARASWATHI S
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
Paras Patel
 
Procedural programming
Procedural programmingProcedural programming
Procedural programming
Ankit92Chitnavis
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
Sachin Sharma
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
Recursion
RecursionRecursion
Recursion
Abdur Rehman
 
Basic Graphics in Java
Basic Graphics in JavaBasic Graphics in Java
Basic Graphics in Java
Prakash Kumar
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Data types in python
Data types in pythonData types in python
Data types in python
RaginiJain21
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
nadarmispapaulraj
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
Gaditek
 
Fundamentals of Language Processing
Fundamentals of Language ProcessingFundamentals of Language Processing
Fundamentals of Language Processing
Hemant Sharma
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
System software - macro expansion,nested macro calls
System software - macro expansion,nested macro callsSystem software - macro expansion,nested macro calls
System software - macro expansion,nested macro calls
SARASWATHI S
 
Compiler vs interpreter
Compiler vs interpreterCompiler vs interpreter
Compiler vs interpreter
Paras Patel
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Basic concepts of object oriented programming
Basic concepts of object oriented programmingBasic concepts of object oriented programming
Basic concepts of object oriented programming
Sachin Sharma
 
Basic Graphics in Java
Basic Graphics in JavaBasic Graphics in Java
Basic Graphics in Java
Prakash Kumar
 

Similar to FUNCTIONS IN R PROGRAMMING.pptx (20)

Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfytttttttttttttttttttttttttttttAll chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
Krushal Kakadia
 
use of Functions to write python program.pptx
use of Functions to write python program.pptxuse of Functions to write python program.pptx
use of Functions to write python program.pptx
rahulsinghsikarwar2
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
KavithaChekuri3
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
AFANJIPHILL
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
nmahi96
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
Learn more about the concepts Functions of Python
Learn more about the concepts Functions of PythonLearn more about the concepts Functions of Python
Learn more about the concepts Functions of Python
PrathamKandari
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
Hattori Sidek
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
Manas40552
 
function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptx
shivas379526
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
C functions
C functionsC functions
C functions
University of Potsdam
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
YOGESH SINGH
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
Ahmad Kamal
 
4. function
4. function4. function
4. function
Shankar Gangaju
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
Mansi Tyagi
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
MehakBhatia38
 
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfytttttttttttttttttttttttttttttAll chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
use of Functions to write python program.pptx
use of Functions to write python program.pptxuse of Functions to write python program.pptx
use of Functions to write python program.pptx
rahulsinghsikarwar2
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
AFANJIPHILL
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
nmahi96
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
Learn more about the concepts Functions of Python
Learn more about the concepts Functions of PythonLearn more about the concepts Functions of Python
Learn more about the concepts Functions of Python
PrathamKandari
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
Manas40552
 
function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptx
shivas379526
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
YOGESH SINGH
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
Ahmad Kamal
 
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
 FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM) FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)
Mansi Tyagi
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
miki304759
 
Ad

Recently uploaded (20)

How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)WinRAR Crack for Windows (100% Working 2025)
WinRAR Crack for Windows (100% Working 2025)
sh607827
 
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
Interactive odoo dashboards for sales, CRM , Inventory, Invoice, Purchase, Pr...
AxisTechnolabs
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Ad

FUNCTIONS IN R PROGRAMMING.pptx

  • 2. INTRODUCTION  A function is a set of statements organized together to perform a specific task.  R has a large number of in-built functions and the user can create their own functions.  In R, a function is an object so the R interpreter is able to pass control to the function , along with arguments that may be necessary for the function to accomplish the actions.
  • 3. FUNCTION DEFINITION  An R function is created by using the keyword ‘function’. Syntax:
  • 4. FUNCTION COMPONENTS  The different parts of a function are- Function Name – This is the actual name of the function. It is stored in R environment as an object with this name. Arguments – An argument is a placeholder. When a function is invoked ,you pass a value to the argument. Arguments are optional; that is, a function may contain no arguments. Also arguments can have default values.
  • 5. Continued:- Function Body – The function body contains a collection of - statements that defines what the function does. Return Value – The return value of a function is the last expression in the function body to be evaluated.
  • 6. BUILT-IN FUNCTION  R has many in-built functions which can be directly called in the program without defining them first.  Simple examples of in-built functions are seq(),mean(),max(),sum() and paste() etc.  They are directly called by user written programs.
  • 8. USER-DEFINED FUNCTION  User defined functions are specific to what a user wants.  Once its created they can be used like the built-in functions. Example:-
  • 9. CALLING A FUNCTION  It is nothing but calling the original function with a valid number of arguments.  A function can be called with an argument ,without an argument and with a default value as well.  The arguments to a function call can be supplied in the same sequence as defined in the function or they can be supplied in a different sequence but assigned to the names of the arguments.  We can define the value of the arguments in the function definition and call the function without supplying any argument to get the default result . we can also call such functions by supplying new values of the argument and get non default result.
  • 10. Continued:- 1. Calling a function Output:
  • 11. Continued:- 2. Calling a function without an argument Output:
  • 12. Continued:- 3. Calling a function with argument values(by position and by name) Output:
  • 13. Continued:- 4. Calling a function with Default argument Output:
  • 14. Lazy Evaluation of function  Arguments to functions are evaluated lazily, which means so they are evaluated only when needed by the function body.
  • 15. RECURSIVE FUNCTIONS  It is a type of looping technique.  It exploits the basic working of function in R.  Recursion is when the function calls itself.  This forms a loop, where every time the function is called , it calls itself again and again and this technique is known as recursion.  Recursive functions call themselves. They break down the problem into smaller components. The function() calls itself within the original function() each of the smaller components. After this, the results will be put together to solve the original problem.
  • 16. Continued:-  Key features  The use of recursion, often, makes the code shorter and it looks cleans.  It is a simple solution for a few cases.  It expresses in a function that calls itself.  Applications  Recursive functions are used in many efficient programming techniques like dynamic programming language(DSL) or divide and conquer algorithms.  In dynamic programming, for both top-down as well as bottom-up approaches , recursion is vital for performance.
  • 18. KEY POINTS TO REMEMBER 1. What is a Function 2. Definition 3. Syntax 4. Function components 5. Built-in function 6. User-defined function 7. Function call 8. Recursive Function 9. Examples
  • 19. TASK 1.Create a function for rectangle , calculate the area and print the result. 2.Create a function to check whether the given number is odd or even.