Short Introduction to R (Tidyverse) — Crash Course

A three-part introductory course to R and the tidyverse, covering data management, visualization, and statistical analysis.

Course Description

This is a short three-part crash course on R and the tidyverse. The course was originally developed for the 2024 Yale Prediction Competition and is aimed at students who are new to R but may already have some familiarity with programming concepts or applied methods in the social sciences.

The course uses a single running example throughout all three sessions: the Eurovision Song Contest voting dataset. This makes it easy to follow the logic from data import to statistical model in one coherent workflow.

Each session consists of a slide deck, annotated teaching notes, and a set of exercises.


Sessions

01

Data Management

Import, transform, summarise, join, and reshape data with the tidyverse

Topics: R basics (objects, functions, RStudio) · Packages · Import & export (CSV, TSV, RDS, SPSS, Stata) · glimpse(), arrange(), select(), filter() · mutate() with if_else() and case_when() · summarise() and group_by() · left_join() · pivot_longer() and pivot_wider()
02

Visualization

Build expressive, publication-ready plots with ggplot2

Topics: Grammar of Graphics · ggplot(), aes(), geoms · Bar charts, line charts, histograms, boxplots, scatterplots, heatmaps · facet_wrap() · Scales, labels, and themes · Saving figures with ggsave()
03

Statistical Analysis

Estimate, report, and visualize linear and generalized linear models

Topics: LM vs. GLM · lm() and glm() · Regression tables with texreg and modelsummary · Coefficient plots with modelplot() · Extracting results with broom::tidy() · In-sample and out-of-sample predictions