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

More Related Content

What's hot

3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
krishna singh
 
2 data types and operators in r
2 data types and operators in r2 data types and operators in r
2 data types and operators in r
Dr Nisha Arora
 
JavaScript Variables
JavaScript VariablesJavaScript Variables
JavaScript Variables
Charles Russell
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
Mohammed Sikander
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
WebStackAcademy
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
 
Operators
OperatorsOperators
Python tuple
Python   tuplePython   tuple
Python tuple
Mohammed Sikander
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data Types
Rsquared Academy
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
Anil Pokhrel
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
Prasanna Kumar SM
 
Recursion - Algorithms and Data Structures
Recursion - Algorithms and Data StructuresRecursion - Algorithms and Data Structures
Recursion - Algorithms and Data Structures
Priyanka Rana
 
Array vs array list
Array vs array listArray vs array list
Array vs array list
Ravi Shetye
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
Samiksha Pun
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
WebStackAcademy
 

What's hot (20)

3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
 
2 data types and operators in r
2 data types and operators in r2 data types and operators in r
2 data types and operators in r
 
JavaScript Variables
JavaScript VariablesJavaScript Variables
JavaScript Variables
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
structure and union
structure and unionstructure and union
structure and union
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
Operators
OperatorsOperators
Operators
 
Python tuple
Python   tuplePython   tuple
Python tuple
 
Function
FunctionFunction
Function
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data Types
 
Function in C Programming
Function in C ProgrammingFunction in C Programming
Function in C Programming
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
Methods in C#
Methods in C#Methods in C#
Methods in C#
 
Recursion - Algorithms and Data Structures
Recursion - Algorithms and Data StructuresRecursion - Algorithms and Data Structures
Recursion - Algorithms and Data Structures
 
Array vs array list
Array vs array listArray vs array list
Array vs array list
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 

Similar to FUNCTIONS IN R PROGRAMMING.pptx

Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
Md. Imran Hossain Showrov
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
Krushal Kakadia
 
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
 
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
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
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
Bharath904863
 
User defined functions.1
User defined functions.1User defined functions.1
User defined functions.1
Mohammad Zuber Vohra
 
Function
FunctionFunction
Function
rishabh agrawal
 

Similar to FUNCTIONS IN R PROGRAMMING.pptx (20)

Lecture 11 - Functions
Lecture 11 - FunctionsLecture 11 - Functions
Lecture 11 - Functions
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
 
Ch4 functions
Ch4 functionsCh4 functions
Ch4 functions
 
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
 
function of C.pptx
function of C.pptxfunction of C.pptx
function of C.pptx
 
Functions in C
Functions in CFunctions in C
Functions in C
 
C functions
C functionsC functions
C functions
 
VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1VIT351 Software Development VI Unit1
VIT351 Software Development VI Unit1
 
Functions assignment
Functions assignmentFunctions assignment
Functions assignment
 
4. function
4. function4. function
4. function
 
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)
 
Chapter One Function.pptx
Chapter One Function.pptxChapter One Function.pptx
Chapter One Function.pptx
 
functions.pptx
functions.pptxfunctions.pptx
functions.pptx
 
arrays.ppt
arrays.pptarrays.ppt
arrays.ppt
 
User defined functions.1
User defined functions.1User defined functions.1
User defined functions.1
 
Function
FunctionFunction
Function
 

Recently uploaded

RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 

Recently uploaded (20)

RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 

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.