Skip to content

Data · updated 26 November 2026

R is used for statistics and data analysis. These scenarios cover data handling, performance and reproducibility.

Top 10 R scenario questions

Try each one yourself first, then open the model answer.

1. A loop over a million rows is very slow. How do you speed it up?

Show answer

Use vectorised operations, or data.table or dplyr grouped operations. Avoid growing objects inside the loop.

2. The mean of a column returns NA. Why?

Show answer

There are missing values. Decide how to treat them, then use na.rm = TRUE if excluding them is right.

3. Numbers read from a file behave like categories. What happened?

Show answer

The column was read as text or a factor. Clean it and convert with as.numeric after as.character for factors.

4. Your analysis gives different results each run. How do you make it reproducible?

Show answer

Set a random seed, record package versions with renv, and keep the whole process in scripts.

5. A join unexpectedly multiplies rows. What do you check?

Show answer

Duplicate keys in one or both tables. Verify uniqueness before joining.

6. R runs out of memory loading a huge CSV. What are your options?

Show answer

Read only needed columns, process in chunks, use data.table or Arrow, or query the data in a database.

7. Two numbers that look equal fail an == test. Why?

Show answer

Floating-point precision. Compare with a tolerance, for example all.equal.

8. Your model fits the training data very well but predicts badly. What do you do?

Show answer

It is overfitting. Use cross-validation, simplify or regularise the model and check for data leakage.

9. A p-value is significant after you tried many variables. Can you report it?

Show answer

Not without correction. Multiple testing increases false positives, so adjust the p-values and report what was tested.

10. A chart misleads because the axis is truncated. How would you handle it?

Show answer

Start bar charts at zero, label axes and units clearly, and state any transformation.

Ready to build something great?

Book your free 30-minute consultation today. No obligation, just honest advice.