---
title: "HW 1"
author: "Name here"
date: "Due September 14, 2018"
output: html_document
---

Please use D2L to turn in both the HTML output and your R Markdown file in. Include your code in line in the document.


Fires and smoke are an unfortunate part of the summer in the west. For this HW assignment, we will explore recordings of atmospheric particulate matter less than 2.5 micrometers (PM2.5) recorded in Bozeman.

Below is a function that will scrape hourly PM2.5 recordings from the MT DEQ website.
```{r, echo=T, message=F, warning=F }
library(rvest)
library(dplyr)
scrape_BZNPM_AUG <- function(days){
  # Scrapes hourly PM2.5 readings in Bozeman for August 2018
  # inputs: sequence of days
  # outputs: data frame that contains day, hour, and hourly average PM2.5 concentration.
  smoke.df <- data.frame(day = NULL, hour = NULL, conc = NULL)

  for (d in days){
    bzn_aq <- read_html(paste("http://svc.mt.gov/deq/todaysair/AirDataDisplay.aspx?siteAcronym=BH&targetDate=8/",d,"/2018", sep=''))
    daily.smoke <- cbind(rep(d,24),html_table(bzn_aq)[[1]][,1:2])
    colnames(daily.smoke) <- c('day','hour','conc')
    daily.smoke$conc[daily.smoke$conc == 'DU'] <- 'NA'
    daily.smoke$conc <- as.numeric(daily.smoke$conc)
    smoke.df <- bind_rows(smoke.df,daily.smoke)
  }
  return(smoke.df)
}
air.quality <- scrape_BZNPM_AUG(1:31)
```


#### Q1. Create a ts object (4 pts) 

Use the scaping function to obtain all of the measurements for August 2018 and create a time series object using `ts()` in R.

#### Q2. Create a plot of the monthly time series object (4 pts) 

Along with the plot include informative titles and labels. Also write a 2-3 sentence caption describing the figure.

#### Q3. Worst Day of Pollution (4 pts)

Identify the day during August 2018, that had the worst pollution levels. Please write a few sentences to justify your claim.

#### Q4. (536 Only) Time Series Decomposition (4 pts)

The `decompose()` function will not work due to the NA values in the dataset. Propose and implement an alternative method. Describe what you have done and plot the decomposed time series.



