Nested Functions

What are Nested Functions?

A function is a set of statements that are executed together to achieve a specific goal or task.

In such a situation, we might have to use another function in the current function. This is called nested functions. We will be learning about user-defined functions being used in another user-defined function.

Syntax of a Nested Function

functionName1 <- function(argument1, argument2, ..., argumentN) 
{
  # Statements
}

functionName2 <- function(argument1, argument2, ..., argumentN) 
{
  # Statements
  functionName1(argument1, argument2, ..., argumentN)
}

Let’s take an example of finding the maximum and minimum number in a vector using multiple functions.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy