Chapter 53: R Quiz

R Quiz.

You’ve been learning very systematically with me for quite a while now, so I think you’re ready for a proper mini quiz that covers the most important things we’ve talked about so far.

This is not a scary exam — think of it as a friendly classroom quiz where:

  • I give you 12 questions
  • You try to answer them yourself first (on paper / in your head / in RStudio)
  • Then scroll down to see the answers + explanations
  • At the end I tell you what your score means and which topics you might want to revisit

No pressure, no grades — just a way to see how much you’ve already absorbed and where we should focus next.

Ready? Let’s begin.

──────────────────────────── R Quiz – February 2026 Edition ────────────────────────────

Question 1 What are the two most common assignment operators in R? Which one is considered modern best practice and why?

Question 2 What will be printed?

R

Question 3 What is the difference between paste() and paste0()? Give one situation where you would choose one over the other.

Question 4 What does this line do?

R

Question 5 True or False? In base R, the function mode() returns the statistical mode (most frequent value) of a vector.

Question 6 Which of these lines will not cause an error?

a) if (marks > 80) print(“Good”) b) if (marks > 80) { print(“Good”) } c) ifelse(marks > 80, “Good”, “Try harder”) (when marks is a vector of length 5)

Question 7 What is the main difference between & and && in R?

Question 8 What will be the result of:

R

Why might “Vsk” become NA in some cases?

Question 9 In ggplot2, what is the correct way to add a title and axis labels?

a) title = “My Plot”, x = “X label” b) labs(title = “My Plot”, x = “X label”, y = “Y label”) c) ggtitle(“My Plot”) + xlab(“X”)

Question 10 What does na.rm = TRUE do in mean(), median(), max(), etc.? What happens if you forget it and there is even one NA?

Question 11 What is the biggest practical difference between mean and median when there are outliers?

Give a short example (2–3 sentences).

Question 12 Write one line of code that finds the row in mtcars with the highest mpg value (just the row, not only the value).

(You can use base R or dplyr)

──────────────────────────── Stop here and try to answer first! Then scroll down for solutions + explanations.

─────────────────────────── Answers & Explanations

Q1 ← and = Modern best practice = <- Why? Because = is also used for naming arguments in function calls → using <- everywhere avoids confusion and bugs.

Q2 mean(x) → NA mean(x, na.rm = TRUE) → 7 (average of 5, 8, 3, 12)

Q3 paste() inserts a space (default sep = ” “) between elements paste0() inserts nothing (sep = “”)

Example: paste(“file”, 1, “.csv”) → “file 1 .csv” paste0(“file”, 1, “.csv”) → “file1.csv” → Use paste0() for filenames, codes, URLs

Q4 It creates (or overwrites) a column called grade in data frame df If marks >= 80 → “A” Otherwise → “B”

Q5 False In base R mode() returns the storage mode (“numeric”, “character”, “logical” etc.) There is no built-in function called mode() for statistical mode.

Q6 All three are correct in different contexts:

a) Works if only one line follows (single-line body) b) Always safe (explicit block) c) Correct when you want vectorized result (if marks is a vector)

Q7 & and are vectorized — they compare element-by-element && and || are scalar / short-circuit — they stop at the first FALSE (for &&) or TRUE (for ||) and are meant only for if() / while() conditions.

Q8

R

“Vsk” becomes NA because it was not in the automatically created levels (which are alphabetical unique values from the data).

Q9 b) labs(title = …, x = …, y = …) is the modern ggplot2 way

Q10 na.rm = TRUE removes NA values before calculation If you forget it and there is even one NA → result is NA

Q11 Mean is strongly pulled by outliers (one very large value makes mean much higher than most values). Median is the middle value after sorting — outliers affect it very little. Example: salaries 40k, 50k, 60k, 70k, 1.2 crore → mean ≈ 26 lakh, median ≈ 60k (median is realistic “typical” salary)

Q12 Base R: mtcars[which.max(mtcars$mpg), ]

dplyr: mtcars |> slice_max(mpg, n = 1)

Scoring Guide (very relaxed)

  • 10–12 correct → Excellent grasp — you’re ready for real mini-projects
  • 7–9 correct → Solid understanding — small revision on 2–3 topics will make you very confident
  • 5–6 correct → Good start — we should revisit a few core concepts with more exercises
  • <5 correct → Totally normal at this stage — let’s do more targeted practice together

Which questions did you get wrong / feel unsure about?

Tell me:

  • Your score (if you want)
  • Which 2–3 questions were hardest
  • Whether you want more exercises on specific topics (data frames, plotting, statistics, dplyr, etc.)

I can create:

  • 10 more easy–medium exercises
  • A full 30–40 min mini-project quiz
  • Focused drill on one topic (e.g. only ggplot2 or only dplyr filtering)

Just say the word — I’m ready to make the next set exactly for you! 🚀📝

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *