Skip to main content

Recitation 3 -- Working with Tables

Skills: 2

Reading: 4.1

Objectives

  • Practice defining table constants
  • Extract data out of tables to answer questions
  • Filtering, ordering, sorting

I. Introduction (5 minutes)

Overview: Explain that today students will work with tabular data representing information about national parks. They'll learn to define tables as constants, extract information to answer questions, and use table operations like filtering and sorting to analyze the data.

II. Setting Up the Data (10 minutes)

A. Defining a Table Constant

Have students define a table containing information about several national parks:

PARKS = table: name, state, established, area-sq-miles, visitors-2024
row: "Yellowstone", "Wyoming", 1872, 3472, 4500000
row: "Yosemite", "California", 1890, 1168, 3900000
row: "Grand Canyon", "Arizona", 1919, 1904, 6400000
row: "Zion", "Utah", 1919, 229, 4700000
row: "Rocky Mountain", "Colorado", 1915, 415, 4300000
row: "Acadia", "Maine", 1916, 198, 2500000
row: "Great Smoky Mountains", "Tennessee", 1934, 816, 12100000
row: "Bryce Canyon", "Utah", 1928, 56, 2900000
end

Check Understanding: Ask students:

  • "What does each row represent?"
  • "What are the column names and what type of data does each contain?"

B. Understanding Table Structure

Point out that tables have:

  • Columns (name, state, established, area-sq-miles, visitors-2024)
  • Rows (each park is one row)
  • Headers that describe what each column contains

III. Extracting Data from Tables (10 minutes)

A. Accessing Individual Values

Activity: Show students how to extract specific data using row and column access:

# Get the name of the first park
PARKS.row-n(0)["name"]

# Get the number of visitors to Yosemite (row 1)
PARKS.row-n(1)["visitors-2024"]

B. Answering Questions with Data

Question 1: "Which park was established first?"

  • Students should examine the 'established' column to find Yellowstone (1872)

Question 2: "What's the total area of parks in Utah?"

  • Students need to identify Utah parks (Zion, Bryce Canyon) and add their areas: 229 + 56 = 285

IV. Filtering Tables (15 minutes)

Explanation: Introduce the filter-with operation to find rows that meet certain criteria.

Have students write filters to answer specific questions:

# Parks established before 1920
old-parks = filter-with(PARKS, lam(r): r["established"] < 1920 end)

# Parks with more than 4 million visitors
popular-parks = filter-with(PARKS, lam(r): r["visitors-2024"] > 4000000 end)

Check Understanding: Ask:

  • "What does the lambda function do in the filter?"
  • "How many parks are in each filtered table?"

V. Ordering and Sorting Tables (15 minutes)

Sorting

Show students how to sort tables by different columns:

# Sort parks by area (smallest to largest)
parks-by-area = order-by(PARKS, "area-sq-miles", true)

# Sort parks by visitors (largest to smallest)
parks-by-popularity = order-by(PARKS, "visitors-2024", false)

Check Understanding: Ask, "What does the true parameter mean in order-by?"

VI. Recap and Wrap-Up (5 minutes)

Key Points Discussion:

  • Table Constants: How defining structured data as constants makes it reusable
  • Data Extraction: Different ways to access and retrieve specific information
  • Operations and Functions over Tables: Different ways of manipulating data in tables to filter, order, and sort

Reflection Questions:

  • "Which operation was most useful for answering questions about the data?"
  • "What happens if you filter a table and get zero results?"