Week 1 · Tuesday, Sep 29 · Lecture
| Time | What |
|---|---|
| 1:30 | Setup check-in |
| 1:40 | A tour of Positron |
| 1:55 | R as a calculator |
| 2:20 | Variables and assignment |
| 2:45 | Pair exercise: write it, explain it |
Learning goals: use the console and a script, do arithmetic in R, and store values with <-.
Type along. No AI: Positron Assistant and inline suggestions stay off.
⏱ 5 min
On Ed Discussion (today’s check-in thread): how did this morning’s setup go?
🟢 people: sit next to a 🟡 or 🔴 person. We’ll finish the fixes during the exercises today.
Tip
Open your stat266a folder with File → Open Folder… every time you work. Your files and your R session then start in the right place.
Console
Script (.R file)
Important
Your work lives in the script. If it’s only in the console history, it didn’t happen.
R uses the usual order: parentheses, exponents, multiplication and division, then addition and subtraction.
⏱ 4 min
On paper, without running anything, write down what R prints:
Then run the three lines and check. Were you right? If not, why not?
This “predict, then run” habit is the Thursday discussion check. Start practicing it today.
A function takes inputs (arguments) in parentheses:
Not sure what a function does? Type ?log in the console. (Much more on help next week.)
<-<- means “store the value on the right under the name on the left”x appear in the Variables pane.# starts a comment. Use comments to explain why.⏱ 5 min
On paper: what are the values of height, weight, and y after these lines run?
Then run it and check the Variables pane. Did y change when height did?
Names can contain letters, numbers, _ and ., must start with a letter, and are case-sensitive (Age ≠ age).
⏱ 3 min
Which of these are valid names? Predict first, then test.
Pick one style and stick to it. In this course we use snake_case: max_height, temp_celsius.
Tip
A clean restart is a good test. Session → Restart R, then run your whole script from the top. If it still works, your script, not your memory, holds your analysis.
R’s superpowers come from packages, which add functions written by others.
Note
Think of it like a phone app: you install it once, and you open it every time you want to use it.
⏱ 15 min
Part 1, alone (8 min): in week01/temperatures.R, write a script that:
temp_f (pick any value)temp_c: \((F - 32) \times 5/9\)> whether temp_c is above 20Part 2, with a partner (7 min): swap laptops. Without running your partner’s script, predict what each line prints. Then run it. Tell each other one thing that was clear and one thing that could be clearer.
Hint: with temp_f <- 77, you should get temp_c equal to 25.
<- stores a value. Assignment prints nothing.all.equal(), not ==, to compare decimalsinstall.packages() once, library() every sessionNext: Thursday, Oct 1 · Help + Data Structures
Still no AI, including for help. We’ll learn to use the documentation instead.

STAT 266A · Fall 2026 · UC Santa Cruz