SECTION A — R BASICS & DATA STRUCTURES
1. Explain the difference between the following R objects, and provide one
example of each:
a) Vector
b) List
c) Matrix
d) Data frame
e) Factor
2. Why does R not require explicit variable declarations before assignment?
Give two correct and two incorrect assignment examples.
3. Write an R script that:
Asks the user for their name, age, and degree programme
Saves these inputs
Prints a formatted welcome message
4. Identify three challenges you may face when importing data into R (e.g.,
CSV, Excel).
For each challenge:
a) Describe it
b) Show an R solution
c) Explain how the solution fixes the problem
5. What is the difference between working in the Global Environment vs
running code from an R script (.R) file? Why is script-based programming
preferred for reproducibility?
SECTION B — DATA WRANGLING, APPLY FAMILY,
LOOPS, DPLYR
6. Using Base R, write code to:
a) Select columns Name and Marks
b) Filter students with Marks > 70
c) Create a new variable Passed (Marks >= 50)
7. Repeat Question 6 using dplyr (select(), filter(), mutate()).
8. Demonstrate how the following functions work using a numeric vector of
your choice:
a) apply()
b) lapply()
c) tapply()
Explain how they differ.
9. Write R code that:
a) Generates 50 random normal values
b) Uses lapply() to compute mean, sd, and median
c) Stores the results in a named list
10. Write:
a) A for loop that prints all even numbers from 1 to 20
b) An if/else statement that checks whether a value is positive, negative, or zero
Explain how loops + conditionals improve automation.
SECTION C — PROBABILITY, DISTRIBUTIONS &
SIMULATION
11. With code, explain the difference between discrete and continuous
distributions using:
Poisson distribution
Normal distribution
12. Using any dataset (or a vector you generate):
a) Compute the mean
b) Compute the standard error (SE)
c) Explain what the standard error tells us about sampling variability
13. Write R code that:
Generates 1,000 values from rpois(lambda = 4)
Plots a barplot of the frequencies
Interprets the shape of the distribution
14. List three applications of simulation in R, and show one example code
snippet for any simulation use case (e.g., Monte Carlo, bootstrapping, random
data generation).
SECTION D — REGRESSION & MODELING
15. Fit a simple regression model predicting Marks from Hours_Studied.
Explain:
a) Intercept
b) Slope
c) p-value
d) R²
e) What a residual is
16. Fit a multiple regression model predicting Marks using:
Hours_Studied
Attendance
Age
Explain how coefficient interpretation changes when moving from simple → multiple
regression.
17. Write R code for:
a) Residuals vs Fitted plot
b) PACF plot of residuals
Describe the purpose of each diagnostic.
SECTION E — FUNCTIONS, PACKAGES &
GRAPHICS
18. Write an R function that accepts a numeric vector and returns:
Minimum
Maximum
Range
Explain why user-defined functions improve reusability.
19. Explain the steps for using a package in R:
1. Install
2. Load
3. Call functions
Give three packages + what each is used for.
20. Using ggplot2, write code to create:
a) Scatterplot
b) Boxplot
c) Histogram
Each plot must have:
Title
Axis labels
A clear aesthetic
Explain when each plot type is most appropriate.