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 Exercises37,076 Learners
Create Your Free Account
Loved by learners at thousands of companies
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.
How to Write a FunctionFree
Learn why writing your own functions is useful, how to convert a script into a function, and what order you should include the arguments.Why you should use functions50 xpCalling functions100 xpThe benefits of writing functions50 xpConverting scripts into functions50 xpConverting a script to a function100 xpYour first function: tossing a coin100 xpInputs to functions100 xpMultiple inputs to functions100 xpY kant I reed ur code?50 xpData or detail?100 xpRenaming GLM100 xp
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.Default arguments50 xpNumeric defaults100 xpLogical defaults100 xpNULL defaults100 xpCategorical defaults100 xpPassing arguments between functions50 xpHarmonic mean100 xpDealing with missing values100 xpPassing arguments with ...100 xpChecking arguments50 xpThrowing errors with bad arguments100 xpCustom error logic100 xpFixing function arguments100 xp
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.Returning values from functions50 xpReturning early100 xpReturning invisibly100 xpReturning multiple values from functions50 xpReturning many things100 xpReturning metadata100 xpEnvironments50 xpCreating and exploring environments100 xpDo variables exist?100 xpScope and precedence50 xpCan a function find its variables?100 xpCan you access variables from inside functions?100 xpVariable precedence 150 xpVariable precedence 250 xp
Case Study on Grain Yields
Apply your function writing skills to a case study involving data preparation, visualization, and modeling.Grain yields and unit conversion50 xpConverting areas to metric 1100 xpConverting areas to metric 2100 xpConverting yields to metric100 xpApplying the unit conversion100 xpVisualizing grain yields50 xpPlotting yields over time100 xpA nation divided100 xpPlotting yields over time by region100 xpModeling grain yields50 xpRunning a model100 xpMaking yield predictions100 xpDo it all over again100 xpCongratulations50 xp
In the following tracksData Scientist with RData Scientist Professional with RR ProgrammerR Programming
DatasetsSnake River visitsStandard & Poor 500 price/earnings ratiosNASS corn yieldsNASS wheat yieldsNASS barley yields
PrerequisitesIntroduction to the TidyverseIntermediate R
Richie CottonSee More
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.
Don’t just take our word for it
*4.6from 23 reviews
- Carlos A.3 months
con mucha facilidad lo comprendi, muy buen curso
- Nicolas F.4 months
I benefitted so much from this training. This was a weak area for me and I feel so much more confident.
- Kaisar B.4 months
- Aaron P.4 months
Very clear instructions with examples to solidify knowledge
- Edwin A.5 months
This is a recommended introductory course to learn writing function in R.
"con mucha facilidad lo comprendi, muy buen curso"
"I benefitted so much from this training. This was a weak area for me and I feel so much more confident."
Join over 11 million learners and start Introduction to Writing Functions in R today!
Create Your Free Account