
---
title: "Lec 13: In-class Exercise: Single Table Analysis"
output:
  html_document
---

```{r, include=FALSE}
# Do not edit this code chunk
knitr::opts_chunk$set(echo = TRUE, message=FALSE, warning = FALSE)
```

# Today's Dataset

Hospital Cost Report, 2018

Run the code below to load the dataset we will be working with today. 

```{r}
library(tidyverse)
hospitals <- read.csv("data/Hospital_Cost_Report_2018.csv")
```

```{r}
view(hospitals)
```

# Ex 1: What questions (if any) do you have about the pre-assigned reading and pre-class exercise? After sharing your questions with your pair, if you two still have questions, please post them in our in-class questions google doc!






## Ex 2: What's wrong (if anything) with each of the following `select()` functions?

```{r}
hospitals |> select(Number.of.Beds > 100)
hospitals |> select(-rpt_rec_num)
```

## Ex 3: What are some ways to select all four of the `Provider.CCN`, `Fiscal.Year.Begin.Date`, `Fiscal.Year.End.Date`, and `Total.Costs` variables from `hospitals`? Give the code showing how to do this in three different ways.

```{r}
# Write your code below

```

## Ex 4: Write your code to filter to hospitals in Boston, MA and number of beds between 100 and 1500. Return a data frame listing the hospital's name, city, state, and number of beds.

```{r}
# Write your code below

```

# `arrange()`, `group_by()`, `summarize()`, & `mutate()`

## Ex 5: Which city in the US has the most hospitals represented in this dataset?

> Hint: Remember that different states might have cities with the same name! 

Write your data wrangling pseudocode first.






```{r}
# Write your code below

```

## Ex 6: In California, are there more rural or urban hospitals? Do rural or urban hospitals have more beds? Be sure to check for the number of hospitals with bed numbers missing.

Write your data wrangling pseudocode first.






```{r}
# Write your code below

```

## Ex 7: Critical Access Hospitals (CCN.Facility Type: CAH) are expected to have 25 beds or fewer. In each state, which critical access hospital has the most number of beds, and how many beds does it have? Return a data frame listing the hospital's name, state, and number of beds, and order the data frame from most beds to least.

Write your data wrangling pseudocode first.








```{r}
# Write your code below

```

## Ex 8: Which Critical Access Hospitals (CCN.Facility Type: CAH) in California has the highest percentage of beds out of the total beds in California? Return a data frame listing the hospital's name, number of beds, percentage of beds, and order the data frame from the highest percentage to lowest.

Write your data wrangling pseudocode first.








```{r}
# Write your code below

```
