Introduction to Writing Functions in R

Take your R skills up a notch by learning to write efficient, reusable functions.
Start Course for Free
4 Hours14 Videos52 Exercises23,382 Learners
4350 XP

Create Your Free Account

GoogleLinkedInFacebook
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA. You confirm you are at least 16 years old (13 if you are an authorized Classrooms user).

Loved by learners at thousands of companies


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.

  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
  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.
    Play Chapter Now
  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.
    Play Chapter Now
  4. 4

    Case study on grain yields

    Apply your function writing skills to a case study involving data preparation, visualization, and modeling.
    Play Chapter Now
In the following tracks
Data ScientistR ProgrammerR Programming
Collaborators
Marianna Lamnina
Richie Cotton Headshot

Richie Cotton

Curriculum Architect at DataCamp
Richie is a Learning Solutions Architect 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

What do other learners have to say?

I've used other sites—Coursera, Udacity, things like that—but DataCamp's been the one that I've stuck with.

Devon Edwards Joseph
Lloyds Banking Group

DataCamp is the top resource I recommend for learning data science.

Louis Maiden
Harvard Business School

DataCamp is by far my favorite website to learn from.

Ronald Bowers
Decision Science Analytics, USAA