Chapter 11 Functions

A key element of programming: Writing our own functions, rather than using those written by others.

Please note: This chapter was originally placed before Chapter 10 on conditionals. But as functions often require conditionals, it makes more sense to start with conditionals and then proceed to functions.


Recommended background readings for this chapter include:


i2ds: Preflexions

To reflect upon the notion and uses of functions, try answering the following questions:

  • What it the mathematical definition of a function?

  • Which R functions have we been using so far? Where did they come from?

  • Why would we want to write our own functions?

  • What would we need to specify to commission (or document) a new function?


Neth, H. (2021). Data science for psychologists. Social Psychology; Decision Sciences, University of Konstanz.
Wickham, H., & Grolemund, G. (2017). R for data science: Import, tidy, transform, visualize, and model data. O’Reilly Media, Inc.