Intro to This Course;
Getting Started with R

Enrico Toffalini

Why becoming an R user?

  • Mainstream in academia for statistical computing and data science, increasingly used in business. Job market advantage!

  • Free & open-source: wherever you go, R will be with you at no costs (unlike MATLAB, MPLUS, SPSS, etc.)

  • Real programming language: difficult at the beginning, but: 1) gives you lots of flexibility; 2) has transfer on other programming languages (e.g., Python).

  • Vast community support thanks to a large and active community (plus chatGPT, Gemini, Lucrez-IA, etc., know it pretty well!).

  • Huge ecosystem, >23,000 packages on CRAN, more from other sources (e.g., GitHub), to do amazing stuff with statistical data analysis, machine learning, data visualization, developing webapps [shiny], writing reports and even entire books [bookdown, rmarkdown]); also, can integrate with Quarto, GitHub.

  • Facilitates reproducible scientific research by sharing code and workflows.

What you may expect to learn in this course:

  • Executing fundamental operations and using basic functions;

  • Working with essential data types and structures;

  • Gaining some proficiency in managing and manipulating data with vectors and dataframes;

  • Understanding some fundamental concepts of programming.

Over the next two years, following this PhD program, you will or may have the opportunity to use R to perform at least some fundamentals about:

  • Core statistical inference methods;

  • LM/LMM/GLMM: (Generalized) linear (mixed-effects) models;

  • Data visualization using ggplot2;

  • Power analysis & more via data simulation;

  • SEM: Structural Equation Modeling;

  • Conducting meta-analysis.

you may even create greeting cards

you may even create greeting cards

or like fancy infographics

or like fancy infographics

perform fancy moderated meta-analyses

you may create interactive webapps with Shiny


see Shiny gallery


here’s a couple of recent real examples from Psicostat members:

you may create interactive webapps with Shiny

or entire websites and books

examples of other resources that can be created within the R ecosystem, integrating other tools such as GitHub and Quarto:

R + Integrated Development Environment(s)

Make sure you install:

  • R as the programming language interpreter and the basic environment and packages
  • RStudio is the IDE of election to make writing R code easy

Interesting alternatives to installing RStudio:

  • Positron (based on MS Visual Studio Code)
  • Posit.cloud (fully online, actually RStudio)
  • Google Colab (fully online, make sure to set R runtime type; actually a Jupyter notebook)

R Console (just base R)

R Studio (full IDE)

Google Colab (online notebook)

Let’s Test the Environment!

Let’s run a few commands in RStudio to familiarize with its console and see if the installation works properly

rnorm(10) # draw 10 random values from a Standard Normal distribution
 [1]  0.63285715 -0.09089180  0.05989258 -1.98495842 -1.39771385 -1.76343919
 [7] -1.37670755 -0.97808745  0.72135449  0.59570175
?rnorm # open the help tab for the "rnorm" function
round( rnorm(10, mean=100, sd=15) ) # draw 10 values from IQ distribution, round them
 [1] 108 103  81  89 101 121 100 104  97 101


install.packages("psych") # install a package from CRAN
library(psych) # load the newly installed package

fisherz(rho=0.5) # use it to transform a correlation into a Fisher's z
[1] 0.5493061