Week 2 · Tuesday, Oct 6 · 9:50-10:55 am · Self-guided
Work through two lessons on the Intro to R site, on your own:
By 10:55 you should have two proof-of-completion PDFs downloaded.
Important
This is the first graded DS: 3 points. 2 for the printout, 1 for Thursday’s discussion check.
Allowed
?, ??, apropos()Not allowed
Talking through an idea with a neighbor is fine and encouraged. Reading their screen and typing what’s on it is not.
Write down what you expect, then run it.
The exercises are seeded, so your numbers differ from your neighbor’s. There’s no answer to borrow: you have to reason about your version.
Note
This is not busywork. Thursday’s discussion check asks you to predict the output of a line from your own solution without running it. If you predicted while solving, you already practiced.
Tip
Keep a scratch script week02/ds02_notes.R for the things you tried. It’s where your discussion-check answers come from.
| Exercise | The skill |
|---|---|
| 1 — Predict the type | Read ?c, then reason about coercion before running |
2 — sep or collapse? |
Find the answer to a specific question inside a help page |
| 3 — Find the right reader | Find a function you’ve never seen, using ?? |
Exercise 3 is the hard one and the most realistic. That’s the whole job: “there must be a function for this” → find it → read its arguments → use it.
Exercise 1. Your four c() calls are different from everyone’s. Work down the hierarchy:
logical → integer → double → complex → character. The most flexible type present wins. 2L is integer, 2 is double, "2" is character.
Exercise 2. In ?paste, read the Arguments entries for sep and collapse, then run the Examples. Ask yourself: does the result have the same length as the input, or length 1?
Exercise 3. Start with ??"read table" or ?read.table. In Arguments, look for two things: how to say “columns are separated by tabs”, and how to say “decimals are written with a comma”. Then use str() on the result: if you see chr where you expect num, it didn’t work.
Run the routine on yourself:
If you spend more than 10 minutes on one exercise, raise your hand. Being stuck is useful; being stuck for 40 minutes is not.
| Exercise | The skill |
|---|---|
| 1 — Clean a messy column | str(), find the bad value, convert, verify |
| 2 — Scale a sequence | Sequences, and using variables instead of typed numbers |
| 3 — What type are the names? | typeof() on a vector vs. on its names() |
| 4 — Number the months | Built-in constants, names(x) <-, lookup by name |
| 5 — Vector or data frame? | [ ] vs [[ ]] vs $ |
| 6 — Length of a matrix | A matrix is a vector with dimensions |
| 7 — Fill by row | Finding byrow in ?matrix |
| 8 — A list of what you know | Building a named list |
| 9 — Which command made this? | Reading code backwards from its output |
Exercise 1. Order matters: find the row first, fix the value second, convert third. If avg_height is NA, you converted before fixing. Print plants2$height_cm to see which entry isn’t a number.
Exercise 2. from:to and seq(from, to) both work. Use the variable names given, not the values you saw printed — the check runs with different numbers.
Exercise 4. Type month.abb in the console first, then LETTERS. These come with R; nothing to load.
Exercise 5. The rule: one bracket keeps the box, two brackets take the contents out. plants[1] is still a data frame; plants[[1]] is the column. Check each with class(), one at a time.
Exercise 6. Predict before running. A matrix is one long vector with a dim attribute, so length() counts elements, not rows or columns.
Exercise 9. Don’t run the four candidates first. Work out which values must be in the vector, in which order, for column-by-column and for byrow = TRUE. Then check. Two of them may both be right.
By now you should have finished Lesson 3 and be somewhere in Lesson 4.
Behind? That’s fine. Priorities:
Done early? Don’t leave. Walk over to someone who’s stuck and ask them what they’ve tried, don’t tell them the answer. Explaining is how you get the extra point on Thursday.
At the bottom of each lesson page:
The PDF shows your name, which exercises you passed, how many attempts, and your final code for each one.
Warning
Two lessons this week means two PDFs. Do it now, in the room. The site stores your work in your browser: a cleared cache or a different laptop and it’s gone.
Upload to Canvas by Wednesday 11:59 pm
Bring to Thursday’s lecture
On Thursday we go through it on paper, and you’ll be asked to explain a line of your own solution or predict what it prints.
Late: up to 3 days, 5% off per 24 hours. The lowest DS grade is dropped.
See you at 1:30 pm for Exploring Data Frames, where we load real data. Bring your laptop charged, and make sure that CSV is there.

STAT 266A · Fall 2026 · UC Santa Cruz