count

# count :: Table, String -> Table

1 What is the Domain of count?

2 What is the Range of count?

3 What do you suspect the String in the Domain will describe?

Suppose we wanted to know how many animals had 4 legs…​

Type count​(​animals-table, "legs"​) into the Interactions Area and click "Enter"

4 What did the expression produce?

5 How many animals had 4 legs?

6 Think of another question you might be able to answer with the count function.

7 Fill in the blanks with the code you’d write.

function-name (table-name :: Table, column-name :: String)

8 Tables that summarize data with a count are commonly used in the real world. Give two examples of where you’ve seen them before:

  • Example 1:

  • Example 2:

9 Newscasters and journalists often incorporate data into their reporting. How else might they display this information, besides using a table?

first-n-rows

10 Type first-n-rows​(​animals-table, 5​). What happens?

11 If we wanted a table of the first 3 rows of the animals-table, what code would you write?

12 What is the Contract for first-n-rows?

What happens when you type first-n-rows​(​sort​(​animals-table, "pounds", true​), 5​)?

Note: In this case, the output of sort(animals-table, "pounds", true) is the Table first-n-rows is taking in!

★ See if you can figure out how to compose the code that would generate a table of the 10 oldest animals!

function-name (Table, Number)

These materials were developed partly through support of the National Science Foundation, (awards 1042210, 1535276, 1648684, 1738598, 2031479, and 1501927). CCbadge Bootstrap by the Bootstrap Community is licensed under a Creative Commons 4.0 Unported License. This license does not grant permission to run training or professional development. Offering training or professional development with materials substantially derived from Bootstrap must be approved in writing by a Bootstrap Director. Permissions beyond the scope of this license, such as to run training, may be available by contacting contact@BootstrapWorld.org.