---
title: "Math 141 Survey Wrangling 2"
author: "Nate Wells"
date: "2/9/2022"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)

survey <- read_csv("math141survey.csv")
```


1. Sort students by division, and within division, by year.

```{r}
survey %>% 
  arrange(major_division, academic_year) %>% 
  select(major_division, academic_year, everything())
```

2. Find the number of students in each year whose primary mode of transportation is walking.

```{r}
survey %>% 
  group_by(academic_year, transportation) %>% 
  summarize(n = n()) %>% 
  filter(transportation == "Walk")
```


3. Calculate the median number of college applications submitted by students who play Wordle.

```{r}
survey %>% 
  filter(play_wordle == "Yes") %>% 
  summarize(median_apps = median(applications))
```

4. Create a data set consisting only of categorical variables (ordered alphabetically), and with student responses ordered alphabetically, starting with the first variable.

```{r}
survey %>% 
  select(academic_year, coffee_tea, diet, dog_pants, hotdog, major_division, prior_stats, play_wordle, study_place, transportation) %>% 
  arrange(academic_year, coffee_tea, diet, dog_pants, hotdog, major_division, prior_stats, play_wordle, study_place, transportation)
```

5. Identify students whose social and economic views differ by 2 or more points.

```{r}
survey %>% 
  mutate(diff = abs(social_views - economic_views)) %>% 
  select(social_views, economic_views, diff) %>% 
  filter(diff > 2)
```

6. Create a data set consisting of two variables: Diet and Height (in inches)

```{r}
survey %>% 
  mutate(height_in = height_cm/2.54) %>% 
  select(diet, height_in)
```

7. Count how many students think both that dogs should wear pants on their back legs and that hot dogs are sandwiches.

```{r}
survey %>% 
  filter(hotdog=="Yes") %>% 
  filter(dog_pants == "Back legs") %>% 
  summarize(how_many = n())
```

8. Among students who drink coffee and whose hometime is at least 100 miles from Reed, create a data set that could be used make a scatterplot of bedtime vs. weekly hours spent studying.

```{r}
survey %>% 
  filter(coffee_tea == "Coffee") %>% 
  filter(distance_home_miles > 100) %>% 
  select(bedtime, weekly_study_hours) %>% 
  ggplot(aes(x = bedtime, y = weekly_study_hours))+
  geom_jitter()
```

