R Quiz: Test Your Knowledge of R Programming

Welcome to The Coding College! Are you learning R programming and ready to challenge yourself? This R Quiz is designed to test your understanding of R basics, syntax, data manipulation, and visualization concepts. Whether you’re a beginner or an intermediate learner, this quiz will help reinforce your knowledge.

Take the quiz below and find out how much you’ve learned!

R Quiz Instructions

  • Read each question carefully and choose the correct answer.
  • The quiz is divided into sections based on R topics.
  • Check the answers at the end of each section.
  • No cheating—try to answer first before scrolling down for solutions!

Section 1: Basics of R

Q1. What is R primarily used for?
A. Web development
B. Data analysis and statistical computing
C. Game development
D. Mobile app development

Q2. How do you assign a value to a variable in R?
A. =
B. <-
C. :
D. ==

Q3. What function is used to display the structure of an R object?
A. summary()
B. str()
C. print()
D. typeof()

Section 2: Data Types and Variables

Q4. What is the class of the following object?

x <- c("Apple", "Banana", "Cherry")

A. numeric
B. logical
C. character
D. factor

Q5. Which of the following data types does not exist in R?
A. Integer
B. Boolean
C. Factor
D. Tuple

Q6. How do you check the data type of an object in R?
A. typeof()
B. data_type()
C. class()
D. isType()

Section 3: Data Frames and Lists

Q7. Which function is used to create a data frame in R?
A. data.frame()
B. create_frame()
C. data_table()
D. list_to_frame()

Q8. What does the following code return?

df <- data.frame(Name = c("Alice", "Bob"), Age = c(25, 30))
df$Age

A. A vector containing 25 and 30.
B. A data frame with one column.
C. An error.
D. The structure of df.

Q9. Which of the following is NOT true about lists in R?
A. Lists can contain objects of different types.
B. Lists are created using the list() function.
C. Lists are limited to numeric data only.
D. Lists can contain other lists.

Section 4: Functions and Control Statements

Q10. How do you define a function in R?
A. func myFunction() {}
B. function myFunction <- {}
C. myFunction <- function() {}
D. myFunction = func() {}

Q11. What will the following code output?

x <- 10
if (x > 5) {
  print("x is greater than 5")
} else {
  print("x is less than or equal to 5")
}

A. "x is less than or equal to 5"
B. "x is greater than 5"
C. An error.
D. No output.

Q12. Which of the following loops exists in R?
A. for
B. while
C. repeat
D. All of the above

Section 5: Data Visualization

Q13. Which function is used to create a scatter plot in R?
A. barplot()
B. hist()
C. plot()
D. scatter()

Q14. What does the col parameter in plot() do?
A. Specifies the plot title.
B. Specifies the color of the plot points or lines.
C. Adds gridlines to the plot.
D. Specifies the type of plot.

Q15. How do you add a title to a plot in R?
A. title="My Title"
B. main="My Title"
C. add_title("My Title")
D. plot_title("My Title")

Answers

Section 1: Basics of R

  1. B – R is primarily used for data analysis and statistical computing.
  2. B – In R, the <- operator is used to assign values to variables.
  3. B – The str() function displays the structure of an R object.

Section 2: Data Types and Variables

  1. C – The object is a character vector.
  2. D – R does not have a Tuple data type.
  3. A – The typeof() function checks the data type of an object.

Section 3: Data Frames and Lists

  1. A – The data.frame() function creates a data frame.
  2. Adf$Age returns a vector containing 25 and 30.
  3. C – Lists are not limited to numeric data only.

Section 4: Functions and Control Statements

  1. C – Functions in R are defined using the function() syntax.
  2. B – The output is "x is greater than 5".
  3. D – R supports for, while, and repeat loops.

Section 5: Data Visualization

  1. C – The plot() function is used for scatter plots.
  2. B – The col parameter specifies the color of the plot points or lines.
  3. B – Use the main parameter to add a title to a plot.

How to Make the Most of This Quiz

  1. Practice Actively: Write the code for each question in an R Online Compiler to see the results yourself.
  2. Review Your Mistakes: If you got a question wrong, revisit the relevant topic on our website.
  3. Challenge Yourself: Modify the code snippets to create your own examples and deepen your understanding.

Conclusion

This R Quiz is a great way to test your skills and identify areas where you need more practice. At The Coding College, we aim to make learning R easy and engaging with tutorials, exercises, and quizzes.

Leave a Comment