Course

R from the ground up

The language statisticians reach for when the data arrives

  • Beginner
  • 12 chapters
  • 211 min read

Learn R by writing it: printing and arithmetic, vectors and indexing, truth and missing values, text, data frames, filtering and sorting rows, functions, loops and the apply family, grouped totals and joins, summary statistics and a fitted line, missing values and tidying, ending with a sales report built from all of it.

What You'll Learn

  • Print output with cat, understand the index prefix print adds, and store values with the arrow
  • Build vectors with c, the colon, seq and rep, and index them from one
  • Write conditions with if and else, and test a whole vector with which, any and all
  • Handle NA deliberately instead of letting it poison a total
  • Reshape text with paste, sprintf, substr, strsplit, grepl and gsub
  • Build a data frame from vectors and compute a new column from two others
  • Filter rows with a logical test or subset, and sort them with order
  • Write functions with defaults, and apply one to a vector with sapply and vapply
  • Repeat work with for and while, and steer it with next and break
  • Summarise per group with aggregate, count with table, and join two tables with merge
  • Describe a column with mean, median and sd, and fit a straight line with lm
  • Find and handle missing values, and tidy duplicates with unique, setdiff and intersect
  • Write a formatted report: a table, a loop of sprintf lines, totals per group and a share

Prerequisites

  • No programming experience needed — this course starts at the first line
  • Any other language you know will make the early chapters quick
  • No statistics background is assumed; the statistics chapter explains its own terms

Course Content

  1. 01
    Your first R

    What R is for, the two ways to print something, how the arrow stores a value, and the arithmetic every lesson after this one is built on.

    Beginner · 14 min read

    Not started
  2. 02
    Vectors: R thinks in rows of values

    The vector is the one building block R is made of: how to build one, how to reach into it, and why arithmetic on a whole vector needs no loop.

    Beginner · 16 min read

    Not started
  3. 03
    Truth, missing values and choices

    Comparisons that answer TRUE or FALSE, tests over a whole vector, if and else, and NA — the third answer that means "not known".

    Beginner · 15 min read

    Not started
  4. 04
    Text you can reshape

    Gluing text together with paste and sprintf, measuring and slicing it, and taking it apart with strsplit, grepl, sub and gsub.

    Beginner · 16 min read

    Not started
  5. 05
    Data frames: tables you can compute on

    The table shape R is built around: build one from named vectors, reach into a column with the dollar sign, add a computed column, and read it back.

    Intermediate · 18 min read

    Not started
  6. 06
    Choosing, sorting and filtering rows

    Keeping the rows that pass a test, asking the same question with subset, picking columns, and sorting a table by one of them.

    Intermediate · 17 min read

    Not started
  7. 07
    Naming your own work

    Writing functions of your own: arguments with defaults, the value that comes back, and handing a function to sapply, vapply and Reduce.

    Intermediate · 18 min read

    Not started
  8. 08
    Loops, lists and the apply family

    Repeating work with for and while, steering a loop with next and break, and knowing when lapply or sapply says the same thing better.

    Intermediate · 18 min read

    Not started
  9. 09
    Groups, counts and joined tables

    Totals per group with aggregate, counts with table, and merge — the one call that brings a price list from another table into your orders.

    Advanced · 19 min read

    Not started
  10. 10
    Summary statistics and one straight line

    The five numbers worth knowing first, then lm: fitting a straight line to two columns and reading its intercept, slope and r squared.

    Advanced · 20 min read

    Not started
  11. 11
    Missing values, duplicates and tidying

    Finding the holes in a table with is.na, working around them with na.rm and filtering, and tidying duplicates with unique, setdiff and intersect.

    Advanced · 18 min read

    Not started
  12. 12
    Capstone: a sales report in base R

    Everything at once: a small table, a computed column, one formatted report line per row, per-region totals, the best seller and a share of the total.

    Advanced · 22 min read

    Not started