R function with return value
In this scenario, we will use the return statement to return some value
Syntax:
function_name <- function(parameters) {
statements
return(value)
}
function_name(values)
Where,
- function_name is the name of the function
- parameters are the values that are passed as arguments
- return() is used to return a value
- function_name(values) is used to pass values to the parameters
Example: R program to perform addition operation with return value
R
# define addition function # perform addition operation on two values addition= function (val1,val2) { # add add=val1+val2 # return the result 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.