Chapter 11 Conditionals

This chapter starts a new part: Basics of programming.

Overview of chapters in this part:

  • Chapter 11 introduces conditionals (for distinguishing between cases)
  • Chapter 12 introduces functions (for creating our own functions)
  • Chapter 13 introduces iteration (for executing code repeatedly).

Conditional statements allow distinguishing between cases and perform corresponding computations. In both spoken and computer languages, such constructs are typically signalled by “if-then.”

Please note: This chapter was originally placed after Chapter 12 on functions. But as functions often require conditionals, it makes more sense to start with the latter.


Recommended background readings for this chapter include:


i2ds: Preflexions

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

  • What is the function of if-then statements?

  • What feature could serve the same function? (Hint: Think base R…)


Neth, H. (2022a). 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.