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.
Awakening
How a koan checks your answers, and R's first ideas: everything is a vector, types, NA and NULL.
Numbers
Arithmetic, integers and doubles, rounding, special values, conversion and sequences.
Vectors
Recycling, indexing, changing, logical tests, summaries, sorting and sets.
Strings
Joining, formatting, measuring, splitting and searching text.
Factors
Categorical data: factors, counting with table, and cutting numbers into groups.
Lists
Lists hold anything: indexing with [ and [[, nesting, changing, and flattening.
Matrices
Two-dimensional vectors: building, indexing, and matrix arithmetic.
Data frames
Tables of data: building, selecting, adding, sorting, grouping and merging.
Control flow
if and ifelse, loops, switch, and breaking out.
Functions
Defining functions, arguments, lazy evaluation, closures, the apply family and pipes.
- Functions
- Defaults and missing arguments
- Dots
- Lazy evaluation
- Closures
- The apply family
- Pipes
- Functional tools
Objects
Attributes, S3 classes and generics, inheritance, and S4.
Conditions
Errors, warnings and messages: signaling, catching, cleaning up, and your own condition classes.
Metaprogramming
Code as data: quoting, substitute, building calls, environments, and evaluating code in a data frame.
Dates and times
Dates and their parts, date arithmetic, and times of day.
Puzzles
Small programs that put the path together: read them closely and predict what they do.