Logo

Basics of R for Data Science

PhD Course in Psychological Sciences - University of Padova

Author

Enrico Toffalini

About This Course

This is a short (10 hours) introductory course on R that is offered within the PhD program in Psychological Sciences (University of Padova). The course is aimed to prepare students for many future methodological courses in this program, where R is used extensively. R is a high-level open-source programming language that is widely used in academic research, but also increasingly adopted in business for data science. It has a large ecosystem of libraries and tools that allow you to perform flexible and powerful data analysis. RStudio is a popular IDE (Integrated Development Environment) which provides an excellent environment for coding, visualization, and report generation when programming in R (and in other languages).

The primary resource for the course is the online book available on GitHub: Introduction2R

Dates and Rooms

Day Time Room
18/11/2024 14:30-16:30 4N
19/11/2024 14:30-16:30 4N
25/03/2024 09:00-12:00 4T
26/03/2024 14:00-17:00 4M

Getting Started

  1. Bookmark the Course Homepage: Save the URL of the present page https://enricotoffalini.github.io/Basics-R/ for quick access to all course materials.
  2. Install R and RStudio: go to this download page to install R and RStudio Desktop on your computer (further setup instructions can be found in Chapter 1 of Introduction2R)
  3. Optional - check your installation by running this code in your newly installed RStudio, and install a few packages:
pkgs = c("readxl", "psych", "ggplot2")
install.packages(pkgs)

Course Topics

We will explore the development environment, work with basic data structures like vectors, dataframes, matrices, and lists, and learn about essential concepts of programming like conditional statements, loops, and functions. Advanced topics like statistical modelling and data simulation will be covered in future courses and are not presented here (although occasional simple examples may appear).

Introduction to the R Environment and First Steps in R

We will cover the installation of R and see how to organize and manage a work session in R Studio, how to create objects, what are data types, how to perform basic operations on them, and how to import and export data, figures, and workspaces.

Data Structures

We will introduce the main data structures in R and methods for interacting with them effectively. We will focus on vectors, dataframes, lists, and more. Dataframes will be given special attention.

Basics of Programming in R

We will introduce essential programming concepts and their implementation in R, including conditional operations (such as if...else), iterative programming (including the for loops and the apply family), and defining custom functions.

Advanced

For more experienced R users, some materials under the Exercises section will provide more stimulating challenges and instructions, even beyond the scope of the present introductory course.

Materials

Slides

Exercises

— The following exercises are fundamental, and they importantly integrate concepts from the slides and introduce new functions and methods that you want to know!

— These other exercises are beyond the scope of this introductory course, but they could be stimulating and useful for more advanced R users:


GitHub repository associated to the present course website: https://github.com/EnricoToffalini/Basics-R

Many thanks and love to Filippo Gambarota for sharing his expertise in using GitHub, Quarto, and creating GitHub Pages websites.