typestar

Language basics

20 steps in 6 sets of R.

R does not really have scalars. A single number is a vector of length one, and once that lands, a lot of R stops being surprising. This tour covers vectors and types, flow control and functions, then a set called Vectorized thinking that is the actual point.

Matrices and lists, text and dates after that. Twenty steps, and the habit it is trying to build is reaching for a whole-vector operation before reaching for a loop.

Start this tour

Vectors & types

Flow & functions

  • ConditionalsBranching, and its vectorized alternative.
  • FizzBuzzThe classic screening exercise, done the way R prefers: over a vector.
  • Primality testTrial division, written vectorized so it tests a whole vector at once.
  • Clamp valuesBounds a vector between a floor and a ceiling using pmin and pmax.
  • Fibonacci vectorBuilds the sequence into a preallocated vector rather than growing one.

Vectorized thinking

Matrices & lists

  • MatricesTwo-dimensional numeric data and matrix algebra.
  • ListsHeterogeneous containers, the shape of every R model object.

Text & dates

Encore

  • csv_summary.RA complete script: read a CSV, summarize each column, print a report.

The other R tours