How to use Function in R

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. The function in turn performs its task and returns control to the interpreter as well as any result which may be stored in other objects.

Example of Function:

Example 1:

> ls()

[1] "a" "b" "c" "x"

Function ls() does not require any argument but most of the Function require argument.

Example 2:

> log(10)

[1] 2.302585

Example 3:

> exp(1)

[1] 2.718282

Example 4: Nested Function

> log(exp(1))

[1] 1

Important things to remember is nested function are evaluated from inside out

Help function:

Using the help function in R we can know about the function detail and what argument required for the function.

Example of help:

> help("log")

You will the information is open in the browser.