Introduction to functions

Functions in any programming language can be described as predefined, reusable code intended to accomplish a specific task. Functions in R can be used by using their name and round brackets right after the that. Inside the brackets, we can specify parameters for the function. One function we have already used extensively is the concatenate function c().

A simple function for example is abs() which is used to get the absolute value of a number. In the following example, the function is given -3 as input and returns the result 3:

Input
abs(-3)
Output
[1] 3
Call existing R code through functions