R Hands-on Workshop Series
Data analysis in R with the tidyverse, built on base R foundations — from messy raw data to tables and plots
Welcome! This hands-on workshop teaches you to analyze data in R using the tidyverse, and the base R foundations underneath it: vectors, types, subsetting, lists, and functions. Each lesson also shows the base R version of key tidyverse steps, so you can read other people’s code (see Base R ↔︎ tidyverse). You will take a realistic, messy outbreak dataset all the way from the raw file to clean data, summary tables, and publication-ready plots — and finish by writing your own functions and loops.
No experience with R or programming is needed.
What you’ll learn
- Set up a project folder and import data from almost any file type
- Inspect a dataset and find its problems before you analyze it
- Clean messy data: fix column names, types, misspellings, impossible values, and duplicates
- Handle missing values and join datasets together
- Understand how R stores data (vectors, lists, data frames), and reshape it between wide and long
- Read base R code and translate it to the tidyverse (and back)
- Summarize data and make a publication-ready “Table 1”
- Make histograms, scatter plots, box plots, bar charts, and epidemic curves with ggplot2
- Write your own functions and loops to automate repeated work
The steps of a data project
Most data projects go through the same steps, whatever the topic. The workshop follows them in order, with one realistic dataset from start to finish:
- Import (Session 1)
- Inspect (1)
- Clean (2, 3)
- Combine (3)
- Reshape (4)
- Summarize (5)
- Visualize (6, 7)
- Save and share (2, 3, 5, 7)
- Automate (8)
Each lesson starts with this strip and highlights the steps it covers.
Start here
- Setup — install R, Positron, and the packages, and download the workshop folder. Please do this before the first session.
- Work through the lessons in order:
| # | Lesson | You will learn |
|---|---|---|
| 1 | R basics, importing, and inspecting data | R basics, packages, project folders, importing and inspecting data |
| 2 | Cleaning | the pipe %>%, clean_names(), mutate(), if_else(), case_when() |
| 3 | Missing data, joins, and export | missing values, duplicates, joins, export() |
| 4 | Data structures | vectors, subsetting, lists, pivot_longer() / pivot_wider() |
| 5 | Summarizing | count(), summarise(), tabyl(), a gtsummary Table 1 |
| 6 | Plotting basics | histograms, scatter plots, box plots |
| 7 | Plotting further | bar charts, colors, epidemic curves, facets |
| 8 | Programming (optional) | functions, if/else, loops, map() |
How each lesson works
Every lesson is split into short parts. Each part follows the same rhythm:
- 👀 Follow along — the instructor live-codes a new skill on the workshop dataset, and you type the same code into your student script (download it from the top of each lesson).
- ✏️ TRY IT — straight away, you do the same thing yourself on a practice dataset (a measles outbreak). Each TRY IT has a ✅ Check so you know whether you got it right, and a solution you can open if you’re stuck.
During live sessions, put up your green sticky note when you finish a TRY IT, or your red one if you need help.
You can! Each lesson page has everything you need: the explanations, the code with its output, every TRY IT, and its solution. Download the student script and work through the page at your own pace.
About this workshop
Created by Max Wegener at the Cushing/Whitney Medical Library, Yale School of Medicine. All datasets are fictional and made for teaching.
The materials are on GitHub.
Questions, suggestions, or found a mistake? Send us feedback by email — we’d love to hear from you.