Creating Functions

In this lesson, we will learn what functions are and how to create them in the R language.

What is a Function?

A function is a set of statements that are executed together to achieve a specific goal or task.

You might remember that everything in R is an object. From this, we can conclude that a function is also an object in R language.

Syntax of a Function

An R function is created by using the keyword function. The basic syntax is as follows:

functionName <- function(argument1, argument2, ..., argumentN) 
{
   # Statements 
}

Let’s have a look at the illustration:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy