koans.app

R Koans

R is a language made by statisticians for working with data. Every value is a vector, missing data is built in, and a data frame holds a table you can filter, group and summarize in a line or two. Scientists, analysts and researchers use it to clean data, run statistics and draw charts. These koans cover vectors, factors, lists and data frames, functions and the apply family, and R’s own object systems, S3 and S4.

78 koans in 15 groups, tested with testthat. Each is a small program whose tests fail: replace every ___ until they pass.

Start the path

Awakening

How a koan checks your answers, and R's first ideas: everything is a vector, types, NA and NULL.

  1. Expectations
  2. Everything is a vector
  3. Types
  4. NA and NULL
  5. Equality
  6. Errors

Numbers

Arithmetic, integers and doubles, rounding, special values, conversion and sequences.

  1. Arithmetic
  2. Integers and doubles
  3. Rounding
  4. Special values
  5. Conversion
  6. Sequences

Vectors

Recycling, indexing, changing, logical tests, summaries, sorting and sets.

  1. Recycling
  2. Indexing
  3. Changing vectors
  4. Logical vectors
  5. Summaries
  6. Sorting
  7. Sets
  8. Vectorized thinking

Strings

Joining, formatting, measuring, splitting and searching text.

  1. paste
  2. Measuring and cutting
  3. Formatting
  4. Splitting
  5. Regular expressions
  6. Dates

Factors

Categorical data: factors, counting with table, and cutting numbers into groups.

  1. Factors
  2. table
  3. cut and ordered factors

Lists

Lists hold anything: indexing with [ and [[, nesting, changing, and flattening.

  1. Lists
  2. Changing lists
  3. Nested lists
  4. Flattening
  5. Names and stacking

Matrices

Two-dimensional vectors: building, indexing, and matrix arithmetic.

  1. Matrices
  2. Matrix arithmetic
  3. Rows and columns
  4. Arrays and outer

Data frames

Tables of data: building, selecting, adding, sorting, grouping and merging.

  1. Data frames
  2. Selecting
  3. Adding columns
  4. Sorting rows
  5. Grouping
  6. Merging
  7. Built-in data

Control flow

if and ifelse, loops, switch, and breaking out.

  1. if and ifelse
  2. Loops
  3. switch
  4. Vectorize instead

Functions

Defining functions, arguments, lazy evaluation, closures, the apply family and pipes.

  1. Functions
  2. Defaults and missing arguments
  3. Dots
  4. Lazy evaluation
  5. Closures
  6. The apply family
  7. Pipes
  8. Functional tools

Objects

Attributes, S3 classes and generics, inheritance, and S4.

  1. Attributes
  2. S3 classes
  3. Generics and inheritance
  4. S4 classes

Conditions

Errors, warnings and messages: signaling, catching, cleaning up, and your own condition classes.

  1. Warnings and messages
  2. tryCatch
  3. Custom conditions
  4. on.exit

Metaprogramming

Code as data: quoting, substitute, building calls, environments, and evaluating code in a data frame.

  1. Quoting
  2. substitute
  3. Building calls
  4. Environments
  5. Evaluating in data

Dates and times

Dates and their parts, date arithmetic, and times of day.

  1. Date parts
  2. Date arithmetic
  3. Times

Puzzles

Small programs that put the path together: read them closely and predict what they do.

  1. FizzBuzz
  2. Word frequencies
  3. Anagrams
  4. Run-length encoding
  5. The sieve of Eratosthenes