Selected Past Exam Questions for Midterm
DANL 101 · Fall 2026
These 21 questions review the Fall 2026 midterm coverage: Lectures 1–6, through Data Types, Databases, and Keys, including left_join().
This is an untimed question bank, not a prediction of the midterm’s questions or topic weights. It does not cover every item in the current guide. Answer each question before opening its solution. Assume dplyr and readr are loaded when their functions are used. All tables needed to answer the questions appear below; no data downloads are needed.
Tools and R fundamentals
Question 1 — Multiple choice: version control
Which version-control tool allows users to track, compare, and merge code changes?
A. GitHub
B. Git
C. R
D. Stack Overflow
B. Git. Git tracks versions and supports comparing and merging changes. GitHub hosts Git repositories and provides collaboration features.
Question 2 — Multiple choice: dashboards
Which of the following best defines a dashboard in data analytics?
A. A statistical model used to predict future business performance
B. A database that stores large volumes of raw transactional data
C. A programming language used for building web-based data systems
D. A visual interface that displays key data, metrics, and trends for quick interpretation and decision-making
D. A dashboard brings useful measures and trends together so viewers can monitor a situation and make decisions. A KPI is a measure used to track progress toward a goal; it can appear on a dashboard.
Question 3 — Multiple choice: parameters and arguments
In R, what is the difference between a parameter and an argument in a function?
A. A parameter is the actual input value passed into a function, while an argument is the variable name used inside the function.
B. A parameter is defined in the function’s declaration, while an argument is the actual value supplied when the function is called.
C. Both terms mean the same thing and can be used interchangeably in R.
D. A parameter refers only to numeric inputs, while arguments refer to text inputs.
B. Using the course’s terminology, x and digits are parameter names in round(x, digits = 0). In round(3.14159, digits = 2), the supplied argument values are 3.14159 and 2. The first value is supplied positionally; the second is named.
Question 4 — Short answer: vectorized calculations
Consider the following two vectors, a and b:
a <- c(5, 20)
b <- c(20, 5)What does sqrt(a / b) return?
c(0.5, 2). Division gives c(5 / 20, 20 / 5), or c(0.25, 4). R then takes the square root of each element.
Question 5 — Multiple choice: logical indexing
Consider the following two vectors, x and y:
x <- c(10, 20, 30, 40, 50)
y <- c(1, 2, 3, 4, 5)What does x[y > 3] return?
A. c(3, 4, 5)
B. c(TRUE, TRUE, TRUE, FALSE, FALSE)
C. c(10, 20, 30)
D. c(40, 50)
E. c(30, 40, 50)
D. c(40, 50). The condition y > 3 is c(FALSE, FALSE, FALSE, TRUE, TRUE). Indexing retains the fourth and fifth values of x.
Question 6 — Short answer: a relative pathname
Suppose the absolute pathname for the CSV file custdata.csv uploaded to your Posit Cloud project is:
/cloud/project/mydata/custdata.csv
The working directory for your Posit Cloud project is:
/cloud/project
Using the file’s relative pathname, write R code to read the CSV file as a data frame and assign it to an object named df.
df <- read_csv("mydata/custdata.csv")The path begins inside the working directory, so it has no leading /. read_csv() is from readr and returns a tibble, which is also a data frame. Explicit readr::read_csv() is also correct. This question asks for code; the file does not need to be opened to answer it.
Missing values and data transformation
Question 7 — Multiple choice: a mean with missing data
Consider the following data frame df0:
x (character) |
y (numeric) |
|---|---|
"1" |
4 |
"2" |
NA |
"Na" |
6 |
What is the result of mean(df0$y)?
A. 4
B. NA
C. 5
D. 6
B. NA. By default, mean() returns NA when the vector contains a missing value. To calculate the mean of the observed values, use mean(df0$y, na.rm = TRUE), which returns 5. This calculation does not alter df0. skim() summarizes data; it does not remove the missing values from the original data frame.
Use this setup for Questions 8 and 9:
df <- data.frame(
id = 1:5,
name = c("Anna", "Ben", "Carl", "Dana", "Ella"),
age = c(22, 28, NA, 35, 40),
score = c(90, 85, 95, NA, 80)
)Question 8 — Multiple choice: strict bounds
Which of the following code snippets filters observations where score is strictly between 85 and 95 (i.e., excluding 85 and 95)?
A. df |> filter(score >= 85 | score <= 95)
B. df |> filter(score => 85 | score =< 95)
C. df |> filter(score > 85 | score < 95)
D. df |> filter(score > 85 & score < 95)
E. df |> filter(score >= 85 & score <= 95)
F. df |> filter(score => 85 & score =< 95)
D. Both strict inequalities must hold, so use &, >, and <. Only Anna, whose score is 90, remains. filter() keeps rows with a TRUE condition; a missing score does not satisfy the condition.
Question 9 — Multiple choice: renaming
Which of the following code snippets correctly renames the variable score in df to exam_score?
A. df |> rename(score = exam_score)
B. df |> rename(exam_score = score)
C. df |> rename("exam_score" = "score")
D. df |> rename(df, exam_score = score)
E. Both B and C
E. Both B and C use the direction new_name = old_name. B is the usual unquoted form. The pipe supplies the data frame, so D incorrectly repeats it. A reverses the renaming direction.
Question 10 — Multiple choice: OR and missing values
The data frame students contains:
sid |
name |
credits |
gpa |
|---|---|---|---|
| 101 | Ava | 12 | 3.2 |
| 102 | Blake | 15 | 2.9 |
| 103 | Ava | NA |
3.8 |
| 104 | Diego | 18 | NA |
| 105 | Eli | 9 | 3.5 |
Which expression keeps only observations where credits is not missing or name is "Ava"?
A. students |> filter(credits == NA & name == "Ava")
B. students |> filter(credits == NA | name == "Ava")
C. students |> filter(credits != NA & name == "Ava")
D. students |> filter(credits != NA | name == "Ava")
E. students |> filter(is.na(credits) & name == "Ava")
F. students |> filter(is.na(credits) | name == "Ava")
G. students |> filter(!is.na(credits) & name == "Ava")
H. students |> filter(!is.na(credits) | name == "Ava")
H. !is.na(credits) tests for observed credits and | requires at least one condition to be true. All five rows remain: four have observed credits, and student 103 is named Ava. Option F happens to retain both Ava rows, but excludes the other students, so it is incorrect. Compare with NA using is.na(), not == NA or != NA.
Use this setup for Questions 11–12:
flights_df <- data.frame(
origin = c("JFK", "LGA", "JFK", "EWR", "LGA", "EWR"),
dest = c("LAX", "ORD", "LAX", "MIA", "ORD", "SEA"),
dep_delay = c(10, 45, 5, 60, 45, 20)
)origin and dest are character variables; dep_delay is numeric.
Question 11 — Multiple choice: sorting with ties
Which of the following code snippets arranges the observations first by origin in ascending order, and then by dep_delay in descending order?
A. flights_df |> arrange(origin, -dep_delay)
B. flights_df |> arrange(origin, desc(dep_delay))
C. flights_df |> arrange(desc(origin), dep_delay)
D. flights_df |> arrange(desc(origin), desc(dep_delay))
E. Both A and B
E. Both expressions sort origins as EWR, JFK, LGA, with descending delays within each origin: 60, 20; 10, 5; 45, 45. Negating works here because delay is numeric; desc() states the descending direction explicitly.
Question 12 — Multiple choice: unique combinations
Which of the following expressions correctly returns all unique origin–destination combinations from flights_df?
A. flights_df |> distinct(origin, dest)
B. flights_df |> select(origin, dest)
C. flights_df |> filter(!is.na(origin), !is.na(dest))
D. flights_df |> distinct()
E. Both A and D
A. The result has four pairs: JFK–LAX, LGA–ORD, EWR–MIA, EWR–SEA. select() alone leaves duplicate pairs. distinct() with no arguments checks all three columns: the two JFK–LAX rows have different delays, so both remain. Thus D does not produce one row per origin–destination pair.
Question 13 — Multiple choice: keeping columns
Consider the following data frame students:
Name |
Age |
Major |
GPA |
|---|---|---|---|
| Alice | 22 | Business Administration | 3.8 |
| Bob | 23 | Accounting | 3.2 |
| Charlie | 21 | Data Analytics | 3.9 |
| Diana | 24 | Economics | 3.5 |
Which of the following R codes will correctly create a new data frame with only the Name and GPA variables?
A. students |> select(Name, GPA)
B. students |> select(-Age, -Major)
C. Both A and B
C. A keeps the two requested columns. B removes the other two columns; because this data frame has exactly these four columns, it returns the same result. Both expressions retain all four students and do not change the original students object unless the result is assigned back to it.
Descriptive statistics
Question 14 — Short answer: a typical value
Why is the median often preferred over the mean as a measure of central tendency when a dataset contains outliers?
The median depends on the middle position in the ordered data, while the mean uses the magnitude of every value. Extreme observations can pull the mean toward them. The median is less sensitive to those observations and can better describe a typical value when a distribution is strongly skewed or contains outliers.
Question 15 — Short answer: standard deviation and variance
In R, what does the function sd(x) compute, and why can it be more useful than var(x)?
sd(x) computes the sample standard deviation, the square root of the sample variance returned by var(x). It measures spread around the mean. Standard deviation has the same units as the observations, so it is often easier to interpret than variance, which has squared units.
For n observed values, sample variance is \sum_{i=1}^{n}(x_i-\bar{x})^2/(n-1). Standard deviation is not the mean of the absolute distances from the mean.
Question 16 — Short answer: IQR and outliers
What is the interquartile range (IQR)? What is the standard deviation (SD)? Explain why the IQR is often preferred over the SD when summarizing the dispersion of a dataset that contains outliers.
The IQR is Q3 - Q1, the spread of the middle 50% of the data. The sample SD is the square root of the sum of squared deviations from the sample mean divided by n-1.
SD uses all observations and gives extreme deviations substantial influence because they are squared. IQR uses the two quartiles, so it is less sensitive to extremes and often better summarizes spread when outliers are present.
Question 17 — Fill in the blank: statistical mode
The ____________________ of a variable is the value that appears most frequently within the set of that variable’s values.
Statistical mode. A dataset can have more than one most frequent value. Base R’s mode() reports an object’s storage mode and does not calculate the statistical mode.
Data types, databases, and keys
Question 18 — Multiple choice: a schema
What is a “Schema” in the context of Big Data Management?
A. The physical hardware used to store the data.
B. A blueprint that defines how data is organized, including fields and data types.
C. The process of deleting old data to make room for new data.
D. The software used to visualize data in charts.
B. A table’s schema describes its structure, including column names and their data types; it may also specify keys and constraints. A schema describes the organization of the data, rather than the individual data values or storage hardware.
Question 19 — Fill in the blank: organized data
____________________ data refers to data that is organized in a predefined format—such as rows and columns with a fixed schema—and is commonly stored in spreadsheets or traditional databases.
Structured data. The predefined fields and types make it possible to consistently store and query records. The definition concerns the organization of the contents; a file extension alone does not establish that its contents are well structured.
Question 20 — Short answer: measurement scales
A fictional user dataset contains these variables:
SubscriptionTier: Standard or Premium, with Standard < Premium in service level.Country: country of residence.LastLoginHour: clock time of the most recent login, measured as hours since midnight on one specified date; midnight is the chosen clock origin.SatisfactionLevel: Very Dissatisfied, Dissatisfied, Neutral, Satisfied, Very Satisfied, in that order. Equal gaps between categories are not assumed.
Classify each variable as nominal, ordinal, interval, or ratio, and briefly explain each choice. For LastLoginHour, treat differences as ordinary same-day clock-time differences.
- Ordinal: the service levels have an order, but the categories do not establish equal numerical gaps.
- Nominal: countries are labels with no intrinsic ranking.
- Interval: same-day differences in hours are meaningful, but midnight is an arbitrary origin. A login at 12:00 is not “twice as late” in the ratio-scale sense as a login at 6:00. A duration measured from an event would be a different variable.
- Ordinal: the satisfaction categories are ordered, but equal distances between them are not established.
These are measurement scales, not R storage types. Numeric coding does not itself turn categories into interval or ratio measurements.
Question 21 — Multiple choice: a left join
Consider the two related data frames:
df_1
id |
name |
age |
|---|---|---|
| 1 | Bob | 19 |
| 2 | Julia | 21 |
| 4 | Zachary | 20 |
df_2
id |
major |
|---|---|
| 1 | Economics |
| 2 | Business Administration |
| 3 | Data Analytics |
Which R code joins the tables to produce this result?
id |
name |
age |
major |
|---|---|---|---|
| 1 | Bob | 19 | Economics |
| 2 | Julia | 21 | Business Administration |
| 4 | Zachary | 20 | NA |
A. df_1 |> left_join(df_2, by = "id")
B. df_2 |> left_join(df_1, by = "id")
C. Both A and B
D. None of the above
A. The left join retains the IDs in df_1 and matches major using ID values, not row positions. ID 4 has no match, so Zachary’s major is NA. ID 3 appears only in df_2 and does not create an extra row. Because df_2 has unique IDs, each left row has at most one match and the result has three rows. Repeated matching IDs in df_2 could multiply rows.
