Basic Commands
Everything you will ever do in R comes down to two basic tasks: creating a new R object, and processing an existing R object. That might sound abstract right now, but it will feel completely concrete by the end of this tutorial.
Rather than explaining all the theory up front, this tutorial builds your understanding gradually, one small step at a time, using the same repeating cycle throughout:
- Do — run a short piece of R code.
- See — observe exactly what R outputs.
- Predict — guess what the next piece of code will do before running it.
- Explain — describe, in your own words, why R behaved that way.
We’ll work through the following topics, roughly in order of increasing complexity:
- Fundamental Interactions — using R as a calculator
- Basic Operators — arithmetic on named objects
- Order of Operations — how R decides what to compute first
- Extended Operators — powers, roots, and other useful functions
- Objects — creating and storing values with
<- - Logical Comparisons — asking R
TRUE/FALSEquestions - Comments — leaving notes in your code
- Environments (optional) — where R keeps your objects
By the end, you’ll be able to run calculations, interpret R’s output, and write your own simple expressions. This is the foundation everything else in this module builds on.
Back to top