---
title: 'Lab 5: Summarizing Data'
format:
  html:
    embed-resources: true
editor: source
knitr:
  opts_chunk:
    message: false
---

###### Question 1
Load the `mosaicData` R package in your Quarto document, and then visit the documentation page for the `SaratogaHouses` data set. 

###### Question 2
Import the Saratoga Houses data set into your environment using the command `SaratogaHouses <- mosaicData::SaratogaHouses` in your Quarto document.
Use `nrow()` to compute the number of rows in `SaratogaHouses`. 

###### Question 3
How old was a "typical" home in Saratoga County during 2006?. To find out, use `summarize()` to compute the median *age* of all the homes in the `SaratogaHouses` data set. 
Be sure to think about what "ingredients" you need to supply for your code to work!

###### Question 4
What was the average amount of living space of a home for sale in Saratoga County during 2006? 
Write your own code "from scratch" to compute this summary. 

Be sure to think about:

1. What variable in the data set measures home size?
2. What function in R calculates the average?
3. What are the units in the output
4. What a good name for your summary would be!

###### Question 5
Does the price of a home depend on the type of heating system it has?

To find out, insert a new code chunk into your Quarto document, and copy the code template below into this new code chunk.

Then, modify the "blanks" in this template to compute the median price of of a home, given its type of heating system.

Be sure to look back at the variables in the data set to figure out which one can tell you what type of heating system a home uses.

###### Question 6
How does the average size of a home depend on the number of bedrooms in the home? Write your own code "from scratch" to compute this summary.
Be sure to think about 

1) Which variable should be the "grouping" variable (i.e., which variable you should look at to figure out which group a home belongs to) and 
2) Which variable should be the summarized variable?


###### Question 7

Which type heating fuel is used the most frequently? We can use the `n()` function to find out!

Investigate by inserting a new code chunk into your Quarto document, and copy the code template below into this new code chunk.

Then, modify the "blanks" in this code chunk to count the number of homes that use electric, gas, or oil as their heating fuel.

Be sure to look back in the documentation for the `SaratogaHouses` data set to figure out which variable measures what kind of fuel a home uses, so you know which variable to group the data by!

###### Question 8
Write your own code "from scratch" to calculate how many homes in the data set do and do not have a waterfront on their property.

###### Question 9
Insert a new code chunk into your Quarto document, and copy code below into that code chunk. Press the green "play" button to run this code, and then explain in words what this code is doing.


###### Question 10
Use the `is.na` function and the `penguins` data set to see only penguins with missing body mass.

###### Question 11
Compute the average flipper length for Adelie, Gentoo and Chinstrap penguins, and the number of penguins of each species. Discard any observations with missing flipper lengths.

