R function without using return

Here without using return function we will return a value. For this just passing the name of the variable that stores the value to returned works.

Syntax:

function_name <- function(parameters) {      

statements

value

}

function_name(values)

where,

  • function_name is the name of the function
  • parameters are the values that are passed as arguments
  • value is the return value
  • function_name(values) is used to pass values to the parameters

Example: R program to perform addition operation without using return function

R




# define addition function
# perform addition operation on two values
addition= function(val1,val2) {   
  # add     
  add=val1+val2
   
  # return the result with out using return
  add
}
 
# pass the values to the function
addition(10,20)


Output:

[1] 30

Return Value from R Function

In this article, we will discuss how to return value from a function in R Programming Language.

Similar Reads

Method 1: R function with return value

In this scenario, we will use the return statement to return some value...

Method 2: R function without using return

...

Method 3: R function to return multiple values as a list

Here without using return function we will return a value. For this just passing the name of the variable that stores the value to returned works....