2
Most read
4
Most read
15
Most read
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

PDF
3 Data Structure in R
PPTX
Chart and graphs in R programming language
PDF
R data types
PPTX
Data Science Process.pptx
PPTX
Python Functions
PPTX
2. R-basics, Vectors, Arrays, Matrices, Factors
PPTX
R language tutorial
PPT
R programming slides
3 Data Structure in R
Chart and graphs in R programming language
R data types
Data Science Process.pptx
Python Functions
2. R-basics, Vectors, Arrays, Matrices, Factors
R language tutorial
R programming slides

What's hot (20)

PPT
RECURSION IN C
PPT
Operator Overloading
PDF
R Programming: Introduction To R Packages
PDF
Python tuple
PPT
12. Indexing and Hashing in DBMS
PPTX
Conditional and control statement
PPT
Programming language design and implemenation
PDF
Introduction to NumPy (PyData SV 2013)
PPS
Java Exception handling
PPT
Requirement specification (SRS)
PPT
Architecture of .net framework
PPTX
GUI components in Java
PPT
Unit 2 Principles of Programming Languages
PPTX
Python Functions
PDF
COMPILER DESIGN- Introduction & Lexical Analysis:
PPT
CS8494 SOFTWARE ENGINEERING Unit-2
PPTX
Command line arguments
PPT
user defined function
PPTX
Dbms slides
PPTX
Data Type Conversion in C++
RECURSION IN C
Operator Overloading
R Programming: Introduction To R Packages
Python tuple
12. Indexing and Hashing in DBMS
Conditional and control statement
Programming language design and implemenation
Introduction to NumPy (PyData SV 2013)
Java Exception handling
Requirement specification (SRS)
Architecture of .net framework
GUI components in Java
Unit 2 Principles of Programming Languages
Python Functions
COMPILER DESIGN- Introduction & Lexical Analysis:
CS8494 SOFTWARE ENGINEERING Unit-2
Command line arguments
user defined function
Dbms slides
Data Type Conversion in C++
Ad

Similar to FUNCTIONS IN R PROGRAMMING.pptx (20)

PPT
Loops and functions in r
PPTX
世预赛买球-世预赛买球比赛投注-世预赛买球比赛投注官网|【​网址​🎉ac10.net🎉​】
PPTX
世预赛买球-世预赛买球竞彩平台-世预赛买球竞猜平台|【​网址​🎉ac123.net🎉​】
PPTX
美洲杯买球-美洲杯买球怎么押注-美洲杯买球押注怎么玩|【​网址​🎉ac99.net🎉​】
PPTX
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
PPTX
世预赛投注-世预赛投注投注官网app-世预赛投注官网app下载|【​网址​🎉ac123.net🎉​】
PPTX
欧洲杯足彩-欧洲杯足彩线上体育买球-欧洲杯足彩买球推荐网站|【​网址​🎉ac55.net🎉​】
PPTX
欧洲杯下注-欧洲杯下注买球网-欧洲杯下注买球网站|【​网址​🎉ac10.net🎉​】
PPTX
欧洲杯买球-欧洲杯买球投注网-欧洲杯买球投注网站|【​网址​🎉ac44.net🎉​】
PPTX
美洲杯投注-美洲杯投注比分-美洲杯投注比分投注|【​网址​🎉ac44.net🎉​】
PPTX
欧洲杯足彩-欧洲杯足彩买球从哪买-欧洲杯足彩买球去哪买|【​网址​🎉ac22.net🎉​】
PPT
Inroduction to r
PPTX
Introduction to R for beginners
PPTX
美洲杯投注-美洲杯投注买球投注官网-美洲杯投注买球官方官网|【​网址​🎉ac99.net🎉​】
PPTX
欧洲杯足彩-欧洲杯足彩买球平台-正规欧洲杯足彩买球平台|【​网址​🎉ac99.net🎉​】
PPTX
欧洲杯体彩-欧洲杯体彩足彩-欧洲杯体彩足彩竞猜|【​网址​🎉ac99.net🎉​】
PPTX
欧洲杯外围-欧洲杯外围赛程-欧洲杯外围压注|【​网址​🎉ac99.net🎉​】
PPTX
欧洲杯足彩-欧洲杯足彩怎么押注-欧洲杯足彩押注怎么玩|【​网址​🎉ac22.net🎉​】
PPTX
世预赛下注-世预赛下注下注平台-世预赛下注投注平台|【​网址​🎉ac44.net🎉​】
PPTX
欧洲杯买球-欧洲杯买球猜球-欧洲杯买球猜球网站|【​网址​🎉ac10.net🎉​】
Loops and functions in r
世预赛买球-世预赛买球比赛投注-世预赛买球比赛投注官网|【​网址​🎉ac10.net🎉​】
世预赛买球-世预赛买球竞彩平台-世预赛买球竞猜平台|【​网址​🎉ac123.net🎉​】
美洲杯买球-美洲杯买球怎么押注-美洲杯买球押注怎么玩|【​网址​🎉ac99.net🎉​】
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
世预赛投注-世预赛投注投注官网app-世预赛投注官网app下载|【​网址​🎉ac123.net🎉​】
欧洲杯足彩-欧洲杯足彩线上体育买球-欧洲杯足彩买球推荐网站|【​网址​🎉ac55.net🎉​】
欧洲杯下注-欧洲杯下注买球网-欧洲杯下注买球网站|【​网址​🎉ac10.net🎉​】
欧洲杯买球-欧洲杯买球投注网-欧洲杯买球投注网站|【​网址​🎉ac44.net🎉​】
美洲杯投注-美洲杯投注比分-美洲杯投注比分投注|【​网址​🎉ac44.net🎉​】
欧洲杯足彩-欧洲杯足彩买球从哪买-欧洲杯足彩买球去哪买|【​网址​🎉ac22.net🎉​】
Inroduction to r
Introduction to R for beginners
美洲杯投注-美洲杯投注买球投注官网-美洲杯投注买球官方官网|【​网址​🎉ac99.net🎉​】
欧洲杯足彩-欧洲杯足彩买球平台-正规欧洲杯足彩买球平台|【​网址​🎉ac99.net🎉​】
欧洲杯体彩-欧洲杯体彩足彩-欧洲杯体彩足彩竞猜|【​网址​🎉ac99.net🎉​】
欧洲杯外围-欧洲杯外围赛程-欧洲杯外围压注|【​网址​🎉ac99.net🎉​】
欧洲杯足彩-欧洲杯足彩怎么押注-欧洲杯足彩押注怎么玩|【​网址​🎉ac22.net🎉​】
世预赛下注-世预赛下注下注平台-世预赛下注投注平台|【​网址​🎉ac44.net🎉​】
欧洲杯买球-欧洲杯买球猜球-欧洲杯买球猜球网站|【​网址​🎉ac10.net🎉​】
Ad

Recently uploaded (20)

PDF
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
PPTX
A Spider Diagram, also known as a Radial Diagram or Mind Map.
PPTX
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
PDF
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
PDF
Cloud Native Aachen Meetup - Aug 21, 2025
PPTX
Human-Computer Interaction for Lecture 2
PPTX
UNIT II: Software design, software .pptx
PPTX
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
PPTX
DevOpsDays Halifax 2025 - Building 10x Organizations Using Modern Productivit...
PDF
AI-Powered Fuzz Testing: The Future of QA
PDF
Coding with GPT-5- What’s New in GPT 5 That Benefits Developers.pdf
PPTX
HackYourBrain__UtrechtJUG__11092025.pptx
PPT
3.Software Design for software engineering
PDF
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
PDF
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
PPTX
ROI from Efficient Content & Campaign Management in the Digital Media Industry
PPTX
Post-Migration Optimization Playbook: Getting the Most Out of Your New Adobe ...
PDF
Top 10 Project Management Software for Small Teams in 2025.pdf
PPTX
Folder Lock 10.1.9 Crack With Serial Key
PDF
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer
Streamlining Project Management in Microsoft Project, Planner, and Teams with...
A Spider Diagram, also known as a Radial Diagram or Mind Map.
WJQSJXNAZJVCVSAXJHBZKSJXKJKXJSBHJBJEHHJB
WhatsApp Chatbots The Key to Scalable Customer Support.pdf
Cloud Native Aachen Meetup - Aug 21, 2025
Human-Computer Interaction for Lecture 2
UNIT II: Software design, software .pptx
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
DevOpsDays Halifax 2025 - Building 10x Organizations Using Modern Productivit...
AI-Powered Fuzz Testing: The Future of QA
Coding with GPT-5- What’s New in GPT 5 That Benefits Developers.pdf
HackYourBrain__UtrechtJUG__11092025.pptx
3.Software Design for software engineering
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
ROI from Efficient Content & Campaign Management in the Digital Media Industry
Post-Migration Optimization Playbook: Getting the Most Out of Your New Adobe ...
Top 10 Project Management Software for Small Teams in 2025.pdf
Folder Lock 10.1.9 Crack With Serial Key
Building an Inclusive Web Accessibility Made Simple with Accessibility Analyzer

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.