The following is the syntax for the function in R programming.
[c]function_name <- function(arg_1, arg_2, ...) {
Function body
}[/c]
In the above syntax, the
function name
will be stored as an object in R environment,
function body
determines exact functioning of the code. The following are the some important predefined functions.
The seq() is function is used to find the sequence of numbers between the range, the following is an example.
[c]
>print(seq(1,10))
1 2 3 4 5 6 7 8 9 10
[/c]
The mean can be calculated as addition of total numbers and divide with total values, the following is an example.
[c]
> print(mean(25:82))
53.5
[/c]
The
max()
function is used to find the maximum value, the following is an example.
[c]
> print(max(25,82,222))
222
[/c]
The sum() function is used to find the addition of given numbers, the following is an example.
[c]
> print(sum(25,82,222))
[1] 329
[/c]