Data Types, Databases, and Keys
October 7, 2026
Discuss: Which source would help you count purchases? Which could help explain why customers liked a product?
Defined rows and columns.
Example: an order table with an ID, date, and total.
Labels or tags organize information, but records can contain different fields.
Example: one app record has a phone-number field, while another does not.
The main content does not follow a fixed table layout.
Example: review text, photos, or videos.
| Kind of variable | What the values mean | Useful comparison |
|---|---|---|
| Nominal | Categories without a ranking | Same or different |
| Ordinal | Categories with a ranking | Higher or lower |
| Interval | Equal differences; no meaningful zero | How much higher or lower |
| Ratio | Equal differences and a meaningful zero | How much; how many times as much |
| Customer | Channel |
|---|---|
| C01 | Website |
| C02 | Store |
| C03 | App |
Discuss: If we label these channels 1, 2, and 3, does that make “average channel = 2” meaningful?
| Response | Order |
|---|---|
| Dissatisfied | Lower |
| Neutral | Middle |
| Satisfied | Higher |
Discuss: On a 1–5 satisfaction scale, does 4 mean “twice as satisfied” as 2?
| Day | Temperature (°F) |
|---|---|
| Monday | 70 |
| Tuesday | 80 |
| Wednesday | 90 |
Check: Which comparison works here—“10°F warmer” or “twice as hot”?
| Customer | Minutes |
|---|---|
| C01 | 0 |
| C02 | 15 |
| C03 | 30 |
| Variable | Example | How to interpret it |
|---|---|---|
| Customer ID | 101, 102, 103 | Labels identifying people |
| Satisfaction score | 1–5 | Ordered responses; gaps may differ |
| Number of orders | 0, 1, 2, 3 | A count with a meaningful zero |
Discuss: Why would an average customer ID be unhelpful, even if R can calculate it?
Note
SQL (Structured Query Language) is commonly used to query database tables. In this course, we use R to practice working with tables.
Reference: IBM · Relational databases
custdata_rev.csv into R as custdata and transformed it with dplyr. We have not used a database yet.| Item | Role | Example |
|---|---|---|
| CSV file | Stores one table as plain text | custdata_rev.csv |
| Database | Stores organized data, often in related tables | A retailer’s customers and orders |
| R data frame | Holds a table in R for analysis | custdata |
| Column | Meaning | Example rule |
|---|---|---|
order_id |
Identifies an order | Required and unique |
customer_id |
Identifies the customer | Uses the agreed ID format |
total |
Order amount in dollars | Numeric; unit documented |
Discuss: A new order repeats an existing order_id and stores total as the text "twenty-five". Which two schema rules does it break?
orders: one row per order| order_id | customer_id | total |
|---|---|---|
| 101 | C01 | 25 |
| 102 | C02 | 40 |
| 103 | C01 | 15 |
| 104 | C03 | 30 |
customers: one row per customer| customer_id | city |
|---|---|
| C01 | Rochester |
| C02 | Buffalo |
| C04 | Albany |
Discuss: Which column could connect an order to its customer’s city?
customer_id.orderscustomer_id tells us which customer placed each order.
C01 appears in two orders because the same customer ordered twice.
customerscustomer_id identifies the customer whose city is recorded.
C01 matches the customer record for Rochester.
orders is our main table; we want to keep its orders.customers supplies the city to attach to each matching order.orders, the table on the left.by = "customer_id" tells R which column’s values to match.left_join() keeps every order and adds city from matching customer records.NA.| order_id | customer_id | total | city |
|---|---|---|---|
| 101 | C01 | 25 | Rochester |
| 102 | C02 | 40 | Buffalo |
| 103 | C01 | 15 | Rochester |
| 104 | C03 | 30 | NA |
NA because C03 has no customer match.Check: Why does C04’s city, Albany, not appear in this result?
Predict: If we start with customers instead, which records would we be trying to keep?
left_join()left_join()
left_join() code.