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
- B – R is primarily used for data analysis and statistical computing.
- B – In R, the
<-
operator is used to assign values to variables. - B – The
str()
function displays the structure of an R object.
Section 2: Data Types and Variables
- C – The object is a character vector.
- D – R does not have a
Tuple
data type. - A – The
typeof()
function checks the data type of an object.
Section 3: Data Frames and Lists
- A – The
data.frame()
function creates a data frame. - A –
df$Age
returns a vector containing 25 and 30. - C – Lists are not limited to numeric data only.
Section 4: Functions and Control Statements
- C – Functions in R are defined using the
function()
syntax. - B – The output is
"x is greater than 5"
. - D – R supports
for
,while
, andrepeat
loops.
Section 5: Data Visualization
- C – The
plot()
function is used for scatter plots. - B – The
col
parameter specifies the color of the plot points or lines. - B – Use the
main
parameter to add a title to a plot.
How to Make the Most of This Quiz
- Practice Actively: Write the code for each question in an R Online Compiler to see the results yourself.
- Review Your Mistakes: If you got a question wrong, revisit the relevant topic on our website.
- 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.