Biostatistics datasets built into R (that you can explore in the browser)
r-tutorial
biostatistics
datasets
teaching
A guided tour of the clinical and biostatistics datasets that ship with R and its packages — infert, esoph, lung, pbc, birthwt, trial and the medicaldata collection — with what each is good for, and a browser playground to try them with no install.
Author
Rverse Analytics
Published
July 10, 2026
One of R’s quiet superpowers for learning and teaching biostatistics is the wealth of real clinical datasets that come built in — no downloads, no cleaning, no data-sharing paperwork. They’re perfect for practising a method, building a reproducible example, or teaching a class. Here’s a tour of the most useful ones, grouped by where they live. Want to poke at them right now? Every dataset below is loadable in our browser R playground — no install.
The datasets package (always available)
R ships with a datasets package that’s loaded by default, so these need no library() call. Two are genuine epidemiology classics:
# infert: a matched case-control study of infertility after abortionstr(infert)
infert is a matched case-control study — ideal for teaching conditional logistic regression and matched designs. Its companion is esoph, a case-control study of oesophageal cancer with age, alcohol and tobacco exposure:
Two more worth knowing: ToothGrowth (a dose–response experiment, good for two-way ANOVA) and sleep (the paired dataset from Student’s original t-test paper).
The survival package (time-to-event gold standards)
If you’re learning survival analysis, these are the datasets every textbook uses. Load the package and they’re available directly:
library(survival)# pbc: the Mayo Clinic primary biliary cirrhosis trialdim(pbc)
time status trt age sex stage
1 400 2 1 58.76523 f 4
2 4500 0 1 56.44627 f 3
3 1012 2 1 70.07255 m 4
4 1925 2 1 54.74059 f 4
5 1504 1 2 38.10541 f 3
6 2503 2 2 66.25873 f 3
pbc (primary biliary cirrhosis, 418 patients) and lung (NCCTG advanced lung cancer, 228 patients) are the two you’ll meet most often. Here’s a Kaplan–Meier plot straight from pbc, comparing survival by sex — the kind of figure these datasets are made for:
fit <-survfit(Surv(time, status ==2) ~ sex, data = pbc)plot(fit, col =c("#2f6fed", "#17a2b8"), lwd =2,xlab ="Days", ylab ="Survival probability",mark.time =FALSE)legend("topright", legend =c("Male", "Female"),col =c("#2f6fed", "#17a2b8"), lwd =2, bty ="n")
Figure 1: Kaplan–Meier survival curves by sex, from the built-in survival::pbc dataset.
Other survival datasets worth exploring: veteran (a lung-cancer trial), colon (adjuvant chemotherapy, with recurrence and death), and ovarian. See our Kaplan–Meier with ggplot2 and Cox proportional hazards posts for what to do next.
The MASS package (a logistic-regression classic)
MASS::birthwt is the canonical teaching dataset for logistic regression: predicting low birth weight from maternal factors like smoking, age and hypertension.
189 births, a binary outcome, and a handful of interpretable predictors — it’s hard to beat for a first logistic model.
gtsummary::trial (for summary and regression tables)
The trial dataset (a simulated 200-patient oncology trial) ships with gtsummary and is purpose-built for practising publication-ready tables. We cover it in depth in the step-by-step Table 1 tutorial — and you can build tables from it live in the gtsummary demo.
medicaldata (a modern teaching collection)
For something more contemporary, the medicaldata package (by Peter Higgins) is a curated collection of real medical datasets chosen specifically for teaching. Highlights:
strep_tb — the 1948 streptomycin trial for tuberculosis, widely considered the first modern randomised controlled trial.
indo_rct — a randomised trial of indomethacin to prevent post-ERCP pancreatitis.
covid_testing — a large, messy, real-world dataset ideal for practising data cleaning.
medicaldata isn’t part of base R, so on your own machine you’d install it once with install.packages("medicaldata"). The easiest way to try it without installing anything is in the browser — see below.
Try them all live, no install
You can load and explore every one of these — including medicaldata — right now in our R playground. It runs real R in your browser via WebAssembly; the datasets section has ready-to-run cells for pbc, birthwt, strep_tb and more. Not sure which test to run on them? Our which test should I use? guide points the way.
Practising is free; production analysis on your own clinical data is where things get real. Our Clinical R toolkit collects the recipes, and we’re here when you need the full analysis.