## Introduction to Function

R Program Functions are the programming artifacts that are supported by the R runtime environment to process the programming logic efficiently. R language supported both native function syntax to create a custom function and system define functions that do some predefined task. Some of the examples of a system define function would be print() function is used to print some data to the R console. Similarly, plot() function is used to create graphical representations using the R language. In R program function there is an object which takes zero or more parameter, to process some programming operations and provides the result as the return value. R program function is useful for reusability and intuitive code writing in R language.

A function should be

- written to carry out a specified task.
- may or may not include arguments
- contain a body
- may or may not return one or more values.

### Functions in R

R has many built-in functions which are used for the specific tasks

Here some important and frequently used functions in Data Science

are listed below

#### 1. mean ()

It is used to find the mean for the object.

`Ex: a<-c(0:10, 40)`

xm<-mean(a)

print(xm)

**Output:**

#### 2. sd ()

It returns the standard deviation of an object.

`a<-c(0:10, 40)`

xm<-sd(a)

print(xm)

**Output:**

#### 3. median()

It returns median.

`a<-c(0:10, 40)`

xm<-meadian(a)

print(xm)

**Output:**

#### 4. sum()

It returns sum.

`a<-c(0:10, 40)`

xm<-sum(a)

print(xm)

**Output:**

#### 5. min()

It returns minimum value.

`a<-c(0:10, 40)`

xm<-min(a)

print(xm)

**Output:**

#### 6. max()

It returns maximum value.

`a<-c(0:10, 40)`

xm<-max(a)

print(xm)

**Output:**

#### 7. is.na ()

It returns the empty rows.

The output is either TRUE OR FALSE.

True for empty rows and False for nonempty ones.

- which (is.na ())- It returns the index of the empty rows.
- help () – used to display the documentation of modules, functions, classes, keywords, etc.

There are many other built-in functions that can be used by importing respective libraries.

13 Online Courses | 20 Hands-on Projects| 120+ Hours| Verifiable Certificate of Completion

4.5

View Course

Apart from these built-in functions, we can create our own functions as per the need.

### Conclusion – R Program Functions

The primary uses of R are and will always be, statistics, visualization, and machine learning, which requires a lot of calculations and visualizations meaning we will require a lot of functions. Few statistical calculations like mean, median, standard deviation, etc. are required in almost all Data Science projects that’s why we have a lot of inbuilt libraries that consist of many functions that are used frequently. If we need new functionality to be implemented, we can create our own functions.

### Recommended Articles

This is a guide to R Program Functions. Here we discuss some important and frequently used functions in R Program and the format for writing our own function. You may also have a look at the following articles to learn more –