HomeRIntroduction to Writing Functions in R

# Introduction to Writing Functions in R

4.7+
30 reviews
Beginner

Take your R skills up a notch by learning to write efficient, reusable functions.

4 Hours14 Videos52 Exercises
42,029 LearnersStatement of Accomplishment

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.
Training 2 or more people?Try DataCamp For Business

## Course Description

Being able to write your own functions makes your analyses more readable, with fewer errors, and more reusable from project to project. Function writing will increase your productivity more than any other skill! In this course you'll learn the basics of function writing, focusing on the arguments going into the function and the return values. You'll be writing useful data science functions, and using real-world data on Wyoming tourism, stock price/earnings ratios, and grain yields.

### .css-1goj2uy{margin-right:8px;}Group.css-gnv7tt{font-size:20px;font-weight:700;white-space:nowrap;}.css-12nwtlk{box-sizing:border-box;margin:0;min-width:0;color:#05192D;font-size:16px;line-height:1.5;font-size:20px;font-weight:700;white-space:nowrap;}Training 2 or more people?

Get your team access to the full DataCamp library, with centralized reporting, assignments, projects and more
Try DataCamp for BusinessFor a bespoke solution book a demo.
1. 1

### How to Write a Function

Free

Learn why writing your own functions is useful, how to convert a script into a function, and what order you should include the arguments.

Play Chapter Now
Why you should use functions
50 xp
Calling functions
100 xp
The benefits of writing functions
50 xp
Converting scripts into functions
50 xp
Converting a script to a function
100 xp
Your first function: tossing a coin
100 xp
Inputs to functions
100 xp
Multiple inputs to functions
100 xp
Y kant I reed ur code?
50 xp
Data or detail?
100 xp
Renaming GLM
100 xp
2. 2

### All About Arguments

Learn how to set defaults for arguments, how to pass arguments between functions, and how to check that users specified arguments correctly.

3. 3

### Return Values and Scope

Learn how to return early from a function, how to return multiple values, and understand how R decides which variables exist.

4. 4

### Case Study on Grain Yields

Apply your function writing skills to a case study involving data preparation, visualization, and modeling.

In the following tracks

Associate Data Scientist in RR DeveloperR Programming

Collaborators

Richie Cotton

Data Evangelist at DataCamp

Richie is a Data Evangelist at DataCamp. He has been using R since 2004, in the fields of proteomics, debt collection, and chemical health and safety. He has released almost 30 R packages on CRAN and Bioconductor – most famously the assertive suite of packages – as well as creating and contributing to many others. He also has written two books on R programming, Learning R and Testing R Code.
See More

## Don’t just take our word for it

*4.7
from 30 reviews
80%
17%
0%
3%
0%
Sort by
• Guisseppe V.
9 months

Very helpful to update my skills in creating functions to my daily job.

• Dan R.
10 months

Very good course!

• Carlos A.

con mucha facilidad lo comprendi, muy buen curso

• Nicolas F.

I benefitted so much from this training. This was a weak area for me and I feel so much more confident.

• Kaisar B.

All good

"Very helpful to update my skills in creating functions to my daily job."

Guisseppe V.

"Very good course!"

Dan R.

"con mucha facilidad lo comprendi, muy buen curso"

Carlos A.