Functions

In this section, we will provide some examples of built-in functions that already exist in R and also construct a user-defined function for a specific task.

A function is a collection of statements put together to do a specific task.

R has a lot of built-in functions and users can define their own functions.

According to their requirement, in R, the interpreter passes control to the function object along with the arguments required for the accomplishment of the task designated for the function. After completing the task, the function returns the control to the interpreter.

The syntax for defining a function is as follows:

>function_name<-function(arg1, arg2,...){ 
>+function body 
>+} 

Here:

  • Function name: This is the name of the defined function ...

Get Learning Quantitative Finance with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.