Camp 1 · Schritt 2 von 12
Calculator and variables
Start with arithmetic, then store results — R's gentle on-ramp from math to data.
R began life as an interactive calculator for statisticians, and it still feels like one. That makes it a wonderfully low-pressure place to start.
R does math
Mostly familiar, with two R-isms:
^is power (2 ^ 10= 1024)%%is modulo, the remainder (17 %% 5= 2)
(cat prints its arguments; the "\n" adds a line break.)
The assignment arrow
R's signature quirk: you store values with <-, an actual arrow pointing
from value to name:
= also works, but <- is the deeply-ingrained R convention — you'll see
it in virtually all R code, so we use it too. Read distance <- 13 as
"distance gets 13."
Naming
total_steps <- 9500 # snake_case is common
avg.pace <- 4.2 # dots are legal in R names (unusual!)R even allows dots in names (avg.pace) — a historical quirk found in few
other languages. snake_case is the modern, safe default.
What is R's conventional assignment operator?
What does 17 %% 5 give in R?
What's next
The idea beneath all of R: the vector.