Data types and data frames - Extra Practice

These questions practice the Taxonomy of Data and the structure of a data frame. For variable types, use continuous numerical, discrete numerical, ordinal categorical, or nominal categorical.

Practice Questions

  1. A researcher records the height, in centimeters, of each student in a class. What is the unit of observation? What variable is recorded, and what type of variable is it?
Show answer

Unit of observation: one student.

Variable: height in centimeters.

Type: continuous numerical. The values are numbers with quantitative meaning, and height can vary along a continuous scale, even if it is rounded when recorded.

  1. A survey asks students to choose one response: “strongly disagree”, “disagree”, “neutral”, “agree”, or “strongly agree.” What type of variable is this?
Show answer

Ordinal categorical. The responses are categories, and the levels have a natural order from strongest disagreement to strongest agreement.

  1. A data set has one row for each penguin and columns for species, bill_length_mm, and island. What is the unit of observation?
Show answer

One penguin. Each row stores values measured on a single penguin.

  1. A classroom roster contains one row per student and columns for name, email, major, and year_in_school. Classify each variable.
Show answer
  • name: nominal categorical. Names are categories with no natural order.
  • email: nominal categorical. Email addresses are labels, not quantities.
  • major: nominal categorical. Majors are categories with no inherent ranking.
  • year_in_school: ordinal categorical if recorded as “first year”, “second year”, etc., because the levels have an order. If recorded as number of semesters completed, it could instead be discrete numerical.
  1. The value 94720 is recorded as a ZIP code. Is this numerical or categorical?
Show answer

Nominal categorical. Although ZIP codes use digits, the magnitude of the number is not quantitatively meaningful. Averaging ZIP codes or subtracting one from another would not answer a meaningful question.

  1. A table shows counts of students by major in the rows and year in school in the columns. Is this table itself a data frame in the tidy sense used in the notes?
Show answer

No. It is an aggregate table, often called a contingency table. The cells are counts for combinations of categories, not values measured on a single observational unit.

A data frame version would likely have one row per student, with columns such as major and year_in_school.

  1. A doctor records the number of visits each patient made to a clinic last year. What type of variable is number_of_visits?
Show answer

Discrete numerical. The values are counts with quantitative meaning, and there are jumps between possible values: 0, 1, 2, and so on.

  1. A study records blood type for each participant: A, B, AB, or O. What are the levels of the variable? What type of variable is it?
Show answer

Levels: A, B, AB, and O.

Type: nominal categorical. These are categories with no natural ordering.

  1. A sensor records outdoor temperature every hour. What type of variable is temperature? Why?
Show answer

Continuous numerical. Temperature takes numerical values whose magnitude has meaning, and the underlying phenomenon varies continuously.

  1. A restaurant tracks whether each order was placed in person, online, or by phone. What type of variable is order_method?
Show answer

Nominal categorical. The values are categories, and there is no natural order among in person, online, and phone.

  1. A data frame contains 500 rows and 6 columns. Each row is one apartment listing. What do the rows, columns, and cells represent?
Show answer
  • Rows: apartment listings, the observational units.
  • Columns: variables measured on each listing, such as rent, neighborhood, or number of bedrooms.
  • Cells: one value of one variable for one apartment listing.
  1. A survey asks people to rate a course as “poor”, “fair”, “good”, “very good”, or “excellent.” Is taking an average of these words meaningful?
Show answer

Not directly. The variable is ordinal categorical: the levels have an order, but the labels are not numbers with meaningful arithmetic. If the categories are coded as 1 through 5, an average can be computed, but that requires an additional modeling choice about spacing between categories.

  1. A data set has one row per flight and variables airline, departure_delay_minutes, destination_airport, and number_of_passengers. Classify the variables.
Show answer
  • airline: nominal categorical.
  • departure_delay_minutes: continuous numerical if measured on a time scale with fractional values possible; often recorded as integer minutes, but the underlying time is continuous.
  • destination_airport: nominal categorical.
  • number_of_passengers: discrete numerical, because it is a count.
  1. A data table has columns labeled green, blue, and total, and rows labeled morning, afternoon, and night. Each cell contains a count of alien sightings. Why is this not a data frame in the sense used in the notes?
Show answer

The columns are not variables measured on a single alien sighting. Instead, the cells contain aggregate counts for combinations of alien color and time of day. A data frame would have one row per sighting and columns such as color and time_of_day.

  1. Convert the alien-sighting table idea into a data frame. If there were 12 green sightings in the morning, what would those 12 rows look like schematically?
Show answer

The unit of observation would be one alien sighting. There would be columns such as color and time_of_day.

The 12 morning green sightings would appear as 12 separate rows, each something like:

color time_of_day
green morning
green morning
green morning

and so on until all 12 sightings are represented.

  1. A student ID number is stored as 303921485. What type of variable is this?
Show answer

Nominal categorical. A student ID is an identifier. The digits do not have quantitative magnitude in the way a measurement or count does.

  1. A study records the number of siblings each student has. What type of variable is this? What possible values might it take?
Show answer

Discrete numerical. It is a count, so possible values are 0, 1, 2, 3, and so on. Values like 1.7 siblings are not possible for a single student.

  1. A hiking app records trail difficulty as “easy”, “moderate”, “hard”, or “expert.” What type of variable is this?
Show answer

Ordinal categorical. These are categories, and they have a natural order from less difficult to more difficult.

  1. A researcher records the amount of rainfall, in inches, at each weather station during a storm. What type of variable is rainfall amount?
Show answer

Continuous numerical. Rainfall amount is quantitative and can vary continuously, even if it is rounded to a fixed number of decimal places.

  1. A professor records each student’s final letter grade: A, B, C, D, or F. What type of variable is this?
Show answer

Ordinal categorical. The values are categories, but they have a natural academic order.

  1. A spreadsheet has one row per county and columns for county_name, population, median_income, and state. What is the unit of observation? Classify the variables.
Show answer

Unit of observation: one county.

  • county_name: nominal categorical.
  • population: discrete numerical, because it is a count of people.
  • median_income: continuous numerical, because income is a quantitative amount.
  • state: nominal categorical.
  1. A survey asks, “How many minutes did you spend commuting today?” The response is typed as a whole number. Is the variable continuous or discrete?
Show answer

This is somewhat defensible either way, depending on what you emphasize.

  • Continuous numerical is defensible because time itself varies continuously.
  • Discrete numerical is also defensible because the recorded values are whole-number minutes with jumps between possible recorded values.

The important point is to explain whether you are classifying the underlying phenomenon or the recorded version of it.

  1. A school data set has one row per classroom. One column is number_of_students; another is teacher_name. What is the unit of observation, and what are the variable types?
Show answer

Unit of observation: one classroom.

  • number_of_students: discrete numerical, because it is a count.
  • teacher_name: nominal categorical, because names are labels with no natural order.
  1. A table has one row for each student and one column for each quiz question. Each cell says whether that student got that question correct. Is this a data frame? What is the unit of observation?
Show answer

It can be treated as a data frame if each row is a student and each column is a variable measured on that student. The unit of observation is one student.

However, for some analyses a different tidy structure might be better: one row per student-question attempt, with columns like student, question, and correct.

  1. A researcher records birth_month as January, February, March, and so on. Is this ordinal or nominal categorical?
Show answer

This is ambiguous.

  • Ordinal categorical is defensible because months have a calendar order.
  • Nominal categorical is also defensible for many analyses because January is not inherently “less than” February in a quantitative sense, and the cycle wraps from December back to January.

The best answer depends on how the variable will be used.

  1. In R, you create hometown <- c("Oakland", "Fresno", "San Diego"). What kind of R object is this, and what type of variable could it represent?
Show answer

It is a character vector in R. As a variable in a data set, hometown would usually be nominal categorical, because the values are names of places with no natural order.

  1. In R, you create siblings <- c(0, 2, 1, 4). What kind of R object is this, and what type of variable could it represent?
Show answer

It is a numeric vector in R. As a variable, number of siblings is discrete numerical, because it is a count.

  1. You combine vectors name, hometown, and siblings into a data frame called my_classmates. If each vector has 6 entries, how many rows and columns should the data frame have? What is the unit of observation?
Show answer

The data frame should have 6 rows and 3 columns.

The unit of observation is one classmate, because each row contains the name, hometown, and sibling count for one person.

  1. Why is “numerical” not the same thing as “written with digits”?
Show answer

A numerical variable has numbers as values and the magnitude of those numbers has quantitative meaning. Some digit strings, like ZIP codes, student ID numbers, phone numbers, or jersey numbers, are labels. They are usually nominal categorical even though they are written with digits.

  1. A data set records the variable shirt_size with levels XS, S, M, L, and XL. What type of variable is it? Are the levels ordered?
Show answer

Ordinal categorical. The values are categories, and the levels have a natural order by size.