Chapter 2 R basics

R project

This chapter provides a very brief introduction to R (R Core Team, 2021), which is a free software environment for statistical computing and graphics.

More specifically, this chapter covers essential concepts and commands of base R, which essentially is R without any additional packages.

Important concepts and contents include:

  • R objects as data vs. functions;
  • creating and changing R objects (by assignment);
  • different types of data (e.g., Boolean values of type logical, numbers of type integer or double, and text of type character);
  • exploring functions and their arguments.

An important constraint of this chapter is that we will deal with vectors as our only data structure. This allows introducing key concepts of R like subsetting (aka. indexing or filtering) and recycling. In the next Chapter 3 on Data structures, we will encounter additional data structures (e.g., matrices, lists, and tables).


Recommended readings for this chapter include:


Before reading, please take some time to reflect upon the following questions:

i2ds: Preflexions

  • What is being manipulated by computer code?

  • What are some differences between a variable and a function?

  • Which types of data can we distinguish?

  • In which order is computer code evaluated?

  • Which windows in the RStudio IDE allow interacting with R?

Note: This chapter is still fragmentary. See Chapter 1: Basic R concepts and commands of the ds4psy book (Neth, 2022a) for a more complete account.


Neth, H. (2022a). Data science for psychologists. Social Psychology; Decision Sciences, University of Konstanz.
R Core Team. (2021). R base: A language and environment for statistical computing. R Foundation for Statistical Computing.