The language
A language for data you can write down as a formula.
R is a language for tables, summaries, and pictures of those tables, from a short script to a paper that cites a model. The lessons teach the syntax. This page is the reason the syntax looks the way it does.
Origins
R descends from S, a language John Chambers and his colleagues began at Bell Labs in the 1970s for interactive data analysis. S treated a data frame and a formula as ordinary values. R kept that shape and made the implementation free.
Ross Ihaka and Robert Gentleman started R at the University of Auckland in the early 1990s. They announced it in 1993. The name is their shared initial. R 1.0.0 was released on 29 February 2000. CRAN, the archive of packages, was already running by then.
The programs in Reticulum use base R, including the stats package that ships with it. Try it runs them with WebR in your browser. A package you would install with install.packages is outside these lessons.
The R Foundation for Statistical Computing holds the copyright in the R sources. The R Core Team maintains the language. A vector is the basic value, which is why a single number in these lessons is still a vector of length one, and why print shows an index.
Beside other languages
R shares the page with languages you may already use for data. It spends its strictness on vectors, missing values, and formulas.
| R | Python | Julia | SQL | |
|---|---|---|---|---|
| Unit of data | An atomic vector, then a data frame of columns. | An object. Arrays arrive through a library. | An array, with multiple dispatch on its type. | A table. The query describes the result. |
| Missing values | NA is part of the vector. It spreads unless you remove it. | None is the absence of an object. NaN is a float. | missing and nothing are distinct from NaN. | NULL is unknown. It fails ordinary comparisons. |
| A model | A formula such as y ~ x, passed to a function. | A method call on an estimator object. | A function, often with a macro for the formula. | An aggregate query, not a fitted line. |
| When it checks | Mostly when the line runs. | Mostly when the line runs. Annotations are optional. | Types can be checked before the program runs. | The engine checks names and types when it plans the query. |
Python is the language beside R in most data work. A data frame in pandas is a cousin of a data frame here, and a notebook can hold either. R keeps the formula and the factor in the language itself. Python usually reaches for a library.
Julia aims at the same numerical work with a type system that can be checked earlier. SQL describes a table transformation and does not fit a line unless you leave the query. R is the shorter path when the next step is a summary, a test, or a plot of a column.
Why someone chooses it
People choose R when the data is already a table and the question is a summary.
- A column is a vector, so the same function that averages two numbers averages a column.
- A formula names the relationship once, and many modeling functions accept that same shape.
- NA is visible. A mean that quietly skipped missing values would be a different function.
- CRAN is where published statistical methods tend to appear first, as an R package.
The tidyverse is a widely used dialect: pipes, tibbles, and a grammar of graphics. These lessons stay in base R so the page does not depend on packages WebR would have to download. You can read a tidyverse script after this room. It is still R.
R is a poor fit when the program is a long-running service, a user interface with no data, or a system that must not copy large vectors. Those programs are usually happier in a language built for that job.
Where it has a following
- Statistics departments and methods papers. New estimators often ship as R packages.
- Biostatistics and public health, including work around surveys and clinical data.
- Ecology, genomics, and other fields with a column for every measurement.
- Some finance and official statistics offices, where a reproducible script is the record.
The pattern is the same in each of these: R is the language people write for the analysis, and faster numerical code sits underneath when a package needs it.
The lessons start at the top of a file. Further continues with methods and tables. Practice covers packages, plots, and summaries.