Module 02 Summary
What this module established
R works on whole vectors, which removes most loops and introduces one hazard: recycling repeats a shorter vector silently when the lengths divide evenly, so a length mismatch can produce a plausible wrong answer with no warning at all.
Carry forward
- Use
<-for assignment and mind the space —x < -5is a comparison and R will not tell you which you meant. - NA is unknown, so any comparison with it returns NA. Test with
is.na(), and decide deliberately what happens to those rows. - Computed decimals are never exactly equal. Use
all.equal(). - Read a function's argument defaults before its description.
na.rm = FALSEis why a mean of a column with one gap returns NA.
Before moving on
Move on when you can explain why sum(scores > 80) returned NA and give two different correct fixes.
