Programming quiz

R Programming Quiz: MCQs on Vectors, dplyr, ggplot2 and Statistics

Check your R skills with 60 questions on vectors and indexing, data types and structures, functions, the apply family, dplyr and pipes, ggplot2 and running statistical tests in R. R outputs were checked by running the code.

✅ Free · no login60 questions⏱ Timer📝 Explanations🖨 Mark sheet & PDFBeginner to intermediate
R Programming Quiz: free online quiz with timer and mark sheet by Codanics
Loading…

R Programming Quiz

60 questions · 7 topics · timer · instant explanations · printable mark sheet.

  • Questions60 in the bank, 10–30 per attempt
  • Levels20 easy · 24 medium · 16 hard
  • TimeAbout 5–20 minutes
  • PriceFree, no login needed
  • Made byDr. Aammar Tufail, Codanics
  • Updated18 November 2026

In short: the R Programming Quiz is a free online multiple-choice quiz by Codanics with 60 questions on vectors and basics; data types and structures; functions and control flow; apply family; data import and dplyr; ggplot2 visualisation; and statistics in R. You choose the number of questions and the difficulty, answer against a timer, see an explanation after every answer and finish with a printable mark sheet.

🚀 Follow Codanics for more free quizzes and lessonsNew quizzes, free lessons, scholarships and PhD positions, straight to your phone.

What the R Programming Quiz covers

R is the language of statistics and research. Its rules can surprise people coming from Python or Excel: indexing starts at 1, vectors recycle, factors behave differently from strings and NA is not the same as NULL.

This quiz covers base R, the tidyverse (dplyr and ggplot2) and the statistical functions you need for a thesis, such as t.test, lm and cor.

  • Vectors and basics 11 questions
  • Data types and structures 8 questions
  • Functions and control flow 7 questions
  • Apply family 8 questions
  • Data import and dplyr 9 questions
  • ggplot2 visualisation 8 questions
  • Statistics in R 9 questions

Who it is for: Researchers, MPhil/PhD students and data analysts who use R for data analysis, and students of the R with Aammar course.

How the quiz works

  1. Type your name if you want it printed on the mark sheet (optional; it never leaves your browser).
  2. Choose 10, 20 or 30 questions, a difficulty (Easy, Mixed or Hard) and the timer: Standard, Relaxed or none.
  3. Answer each question before the timer runs out. Press A–D or 1–4 on a keyboard, or tap an option on your phone.
  4. Read the explanation after every answer, then press Next.
  5. At the end, get your score, grade, topic-wise breakdown and a full answer review. Print it or save it as a PDF.
  6. Retake the quiz for a fresh random set, or practise only the topics you found hard.

Free video lessons from Codanics

Score lower than you hoped? These free lessons from the Codanics YouTube channel cover the same topics, explained step by step.

▶ Full playlist: R with Aammar: complete R programming course
Free on the Codanics YouTube channel, taught in Urdu/Hindi.

Sample questions with answers

Here are 9 questions from the bank, with answers and explanations. The quiz above draws from all 60.

1. What does this R code print? (x <- c(10, 20, 30))
x <- c(10, 20, 30)
x[1]
  1. 20
  2. 10
  3. 30
  4. An error, because indexing starts at 0

Answer: B. 10
R vectors are indexed from 1, so x[1] is the first element, 10. There is no element 0 in R.

2. What does this code return? (c(1, 2, 3, 4) + c(10, 20))
c(1, 2, 3, 4) + c(10, 20)
  1. 11 22 13 24
  2. 11 22 NA NA
  3. 11 22
  4. An error: lengths differ

Answer: A. 11 22 13 24
R recycles the shorter vector: c(10, 20) is reused as 10, 20, 10, 20. Since 4 is a multiple of 2, there is no warning.

3. What is a factor in R mainly used for?
  1. Storing dates and times of day
  2. Storing very large whole numbers
  3. Storing categorical data with fixed levels
  4. Storing named key-value pairs

Answer: C. Storing categorical data with fixed levels
Factors store categories such as gender or region as integer codes plus a set of levels. Models and plots treat them as groups.

4. Which code correctly defines a function that squares its input?
  1. sq = lambda x: x^2
  2. sq <- function(x) x^2
  3. function sq(x) { x^2 }
  4. sq <- def(x) x^2

Answer: B. sq <- function(x) x^2
Functions are created with function(args) body and assigned to a name. def and lambda are Python syntax.

5. What does this code return? (sapply(1:3, function(x) x * 2))
sapply(1:3, function(x) x * 2)
  1. 12
  2. 2 4 6
  3. A list with elements 2, 4 and 6
  4. 1 2 3

Answer: B. 2 4 6
sapply() applies the function to each element and simplifies the result to a vector where possible.

6. In dplyr, which pair of verbs keeps certain rows and certain columns respectively?
  1. summarise() and group_by()
  2. filter() and select()
  3. distinct() and rename()
  4. arrange() and mutate()

Answer: B. filter() and select()
filter() keeps rows that meet a condition; select() picks columns by name. arrange() sorts rows and mutate() adds or changes columns.

7. In ggplot2, what does aes() do?
  1. Adds a title, subtitle and axis labels
  2. Sets the overall theme and fonts of the plot
  3. Maps data columns to visual properties such as x, y and colour
  4. Saves the finished plot to an image file

Answer: C. Maps data columns to visual properties such as x, y and colour
aes() defines aesthetic mappings: which column goes on x, which on y, which controls colour or size, and so on.

8. Which R function fits a linear regression model?
  1. lm()
  2. glm.fit()
  3. linear()
  4. reg()

Answer: A. lm()
lm(y ~ x, data = df) fits an ordinary least squares linear model. summary() on the result shows coefficients and R-squared.

9. What does median(c(3, 1, 4, 1, 5)) return?
  1. 3
  2. 4
  3. 1
  4. 2.8

Answer: A. 3
Sorted, the values are 1, 1, 3, 4, 5, and the middle one is 3. The mean is 2.8.

Free guides and blogs to study

Free tools for your studies and research

Codanics also has 160+ free online tools for students and researchers: statistics calculators, meta-analysis, PDF and writing tools. They run in your browser, with no login.

Browse all free tools →

Frequently asked questions

Is the R Programming Quiz free?

Yes. The R Programming Quiz is completely free, with no sign-up, no login and no limit on attempts.

How many questions are in the R Programming Quiz?

The question bank has 60 multiple-choice questions (20 easy, 24 medium and 16 hard) across 7 topics. Each attempt draws 10, 20 or 30 of them at random, so every attempt is different.

How does the timer work?

Each question has its own countdown: about 25 seconds for easy, 40 for medium and 55 for hard questions, plus 15 seconds when there is code to read. Choose Relaxed to double the time or switch the timer off to study at your own pace. Unanswered questions count as skipped.

Can I get a certificate or mark sheet?

Yes. When you finish, you get a mark sheet with your name, score, grade, time, topic-wise performance and every answer explained. Use Print or save as PDF to keep it. It is a self-assessment result, not an official certificate.

Are the answers and explanations correct?

Every question was written and reviewed for one clearly correct answer, and code questions were checked by running the code. If you think an answer is wrong, tell us on the Codanics WhatsApp channel or in the YouTube comments and we will fix it.

Do I need RStudio to take the R quiz?

No, the quiz runs in your browser. To try the code yourself, use RStudio, Posit Cloud or any R console; the outputs will match the answers.

Does the quiz include the tidyverse?

Yes. It includes dplyr verbs (filter, select, mutate, summarise, group_by), both pipes (|> and %>%) and ggplot2 layers, aesthetics and facets.

Is my data stored anywhere?

No. The quiz runs entirely in your browser. Your name, answers and score are not uploaded. Your best score and settings are remembered only in this browser so you can track your progress.

More free quizzes

See all Codanics quizzes → · Courses · Free tools · Blog

Follow Codanics

Created by Dr. Muhammad Aammar Tufail, Codanics. Published 18 November 2026, last updated 18 November 2026. Found a mistake or want a quiz on another topic? Tell us on the WhatsApp channel or contact us.