Module 02 Knowledge Check
5 questions. Pass mark 4 out of 5. Answer every question before checking the answer key below, then retry after reading the feedback.
1. x <- 5 and x < -5 differ because…
- A. the second is invalid syntax
- B. the first assigns and the second compares
- C. they are identical; the space is style
- D. the second assigns a negative
2. A good comment on a line that removes values of 9999 says…
- A. that values over 5000 are removed
- B. that 9999 is the source system's not-recorded sentinel
- C. which function is being used
- D. who wrote the line
3. visits + c(1, 2, 3, 4) where visits has six elements…
- A. raises an error and stops
- B. returns a length-four result
- C. warns about lengths and still returns a result
- D. silently returns the original vector
4. The correct way to test whether a value is missing is…
- A.
x == NA - B.
is.na(x) - C.
x == 'NA' - D.
length(x) == 0
5. mean(scores) returns NA on a column with one gap because…
- A. the column is the wrong type
- B.
na.rmdefaults to FALSE - C. NA is treated as zero
- D.
mean()requires a data frame
---
Answer Key and Explanations
Check these only after attempting every question.
1. B — the first assigns and the second compares
One space changes assignment into comparison, and R reports no error either way.
2. B — that 9999 is the source system's not-recorded sentinel
The code already says what happens. The comment carries what the code cannot: what the value means.
3. C — warns about lengths and still returns a result
R warns because 6 is not a multiple of 4, but a result still comes back — which is why a recycling warning should be treated as an error.
4. B — is.na(x)
NA is unknown, so x == NA returns NA for every row and no row passes the filter — it looks like there is no missing data.
5. B — na.rm defaults to FALSE
Defaults are decisions the function makes for you. R refuses to average around a hole unless you say so.
Practical Check
Apply this module to your own work: complete the module activity for *R Language Basics*, then write one sentence naming what your result shows and one naming what it does not.
Strong Answer Pattern
A strong answer names the task, the evidence used, the check performed, and the remaining limitation. It avoids "proved", "guaranteed", or "always" unless the evidence genuinely supports it.
