Intro to R

A free, self-guided, interactive course teaching R for reproducible data analysis — write and check real R code in your browser, then use the same code in R and Positron on your own computer.

17 lessons · 10 weeks Runs real R via webR CC BY-NC 4.0

Structure modeled on GAMs in R (Noam Ross et al., CC BY 4.0). Content adapted from R for Reproducible Scientific Analysis (The Carpentries, CC BY 4.0). See full credits.

Lessons by week

Week 01 Getting started · Thu Sep 24 · Tue Sep 29

Thursday: lecture with laptop time. Tuesday: self-guided lesson in the morning, discussion & peer review in the afternoon.

1

Thu Sep 24

Set Up Your Machine for This Course

Install R and Positron, open a course folder, install the packages we'll use, and check that everything works.

Not started
2

Tue Sep 29

R Basics

Self-guided: find your way around Positron, use R as a calculator, compare values, assign variables and manage packages.

Not started

Week 02 Help and data structures · Thu Oct 1 · Tue Oct 6

3

Thu Oct 1

Seeking Help

Build your own paths to answers: read help pages and error messages, and find functions you don't know the name of.

Not started
4

Thu Oct 1

Data Structures

Vectors, data types, coercion, names, factors, lists, matrices, and how a data frame is built from them.

Not started
5

Tue Oct 6

Exploring Data Frames

Load and get oriented in a real dataset: read str() output, look beyond the first rows, add and remove rows and columns, and source scripts.

Not started

Week 03 Control flow and cleaning data in practice · Thu Oct 8 · Tue Oct 13

6

Thu Oct 8

Control Flow

Make decisions with if/else and repeat work with for and while loops, including loops over groups of the gapminder data.

Not started
7

Tue Oct 13

Cleaning Data in Practice: Subsetting

Pick exactly the elements, rows and columns you want with [ ], [[ ]] and $, and use them to clean data one checkable step at a time.

Not started

Week 04 Graphics and vectorization · Thu Oct 15 · Tue Oct 20

8

Thu Oct 15

Graphics with ggplot2

Build plots layer by layer with ggplot2: mappings, geoms, layer order, fixed vs mapped properties, scales, trend lines, facets and labels.

Not started
9

Tue Oct 20

Vectorization

Let R work on whole vectors at once: vectorized arithmetic, recycling, logical vectors and one-line formulas.

Not started

Week 05 Functions and regression in practice · Thu Oct 22 · Tue Oct 27

10

Thu Oct 22

Functions Explained

Package your code into functions: arguments, return values, composition, defensive checks and defaults.

Not started
11

Tue Oct 27

Regression in Practice

Fit a straight line with lm(), read its coefficients, R-squared and p-value, plot it, and learn from its residuals.

Not started

Week 06 Combining data practice I · Thu Oct 29 · Tue Nov 3

12

Thu Oct 29

Writing Data

Save figures and cleaned data from code into results/, and check what you wrote.

Not started
13

Tue Nov 3

dplyr I: filter, select, mutate

Manipulate data frames with dplyr verbs chained by the pipe: filter rows, select columns, add columns and sort.

Not started

Week 07 Combining data practice II · Thu Nov 5 · Tue Nov 10

14

Thu Nov 5

dplyr II: groups and joins

Summarize data by group with group_by() and summarize(), sample within groups, and combine tables with joins.

Not started
15

Tue Nov 10

Reshaping Data with tidyr

Move data between long, wide and intermediate shapes with pivot_longer() and pivot_wider(), and combine reshaping with dplyr.

Not started

Week 08 Your first report · Thu Nov 12 · Tue Nov 17

16

Thu Nov 12 · Tue Nov 17

Reports with Quarto

Write reproducible reports that mix prose, code and results: YAML headers, Markdown, code cells with #| options, inline code, and rendering in Positron.

Not started

Week 09 Code review · Thu Nov 19 · Tue Nov 24

No class Thu Nov 26 (Thanksgiving).

17

Thu Nov 19 · Tue Nov 24

Writing Good Software

Write code other people can read and trust: clear structure, no copy-paste, good names, consistent style, and tests.

Not started

Week 10 Projects · Tue Dec 1 · Thu Dec 3

•

Tue Dec 1

Work on your project

In-class time to work on your project. Bring questions.

•

Thu Dec 3

Project presentations

Present your project to the class.