
---
title: "Problem Set 05"
author: "WRITE YOUR NAME HERE"
date: "Due Friday, October 21, 2016"
output:
  html_document
---


## Please Indicate

* Who you collaborated with. If no one, please indicate so: 
* Approximately how much time did you spend on this problem set: 
* What, if anything, gave you the most trouble: 


## ~~Tips~~ Instructions:

* Knit this file once first and read all the questions before doing any work.
* Then in your console, run all the code contained in grey code blocks in a
linear fashion from start to finish.
* Always `View()` any data sets and read the help file first. For example the help
file for the `profiles` data set below is accessible by typing `?profiles` in the
console after loading the data.


```{r, echo=FALSE, message=FALSE}
# Do not modify any code in this block, however you still need to run it in your
# console to load all the necessary packages.
library(ggplot2)
library(dplyr)

# Packages containing data sets for today
library(okcupiddata)
library(gapminder)
```





## Question 1: Drug Use Amongst OkCupid Users

Let's revisit the 60,000 San Francisco OkCupid users in 2012 and consider the
variable `drug` reflecting users' answers to a question on their drug use.

```{r, echo=FALSE}
# Do not modify any code in this block, however you still need to run it in your
# console to load the profiles data set, which is in the okcupiddata R package.
data(profiles)

# Convert missing values in drugs to an actual category "N/A". You do not need
# to understand this code right now.
profiles <- profiles %>% 
  mutate(drugs=ifelse(is.na(drugs), "N/A", drugs))
```


#### a) 

Type in a series of commands that will output how many men and women there are.

```{r, echo=TRUE}
# Write your code below:

```



#### b)

Create a visualization that shows the distribution of the different responses in 
the variable `drugs`.

```{r, echo=TRUE}
# Write your code below:

```


#### c)

Create a visualization that shows the same information as in part a), but for
men and women separately. Is a man more likely to never use drugs? Or a woman?

```{r, echo=TRUE}
# Write your code below:

```


#### d)

In lines 54-55 above we made sure to convert all missing values, encoded in R
as `NA`, to a specific response value "N/A" i.e. not answered. Why do you think it was
important to do so?







## Question 2: Gapminder

We consider the Gapminder data from Problem Set 04 again.

```{r, echo=FALSE}
# Do not modify any code in this block, however you still need to run it in your
# console to load the gapminder data set, which is in the gapminder R package.
data(gapminder)
```



#### a) 

Output a table that allows you to answer the following two questions on the GDP of countries in the year 2007:

1. What is the richest continent per capita in 2007?
1. Which continent seems to have the most consistent GDP per capita across its constituent countries in 2007?


```{r, echo=TRUE}
# Write your code below:

```









## Question 3: Titanic

Finally, we consider survivor data from the Titanic. This is a data set that comes
with R by default, so we don't need to install any packages

```{r, echo=TRUE}
# Do not modify any code in this block, however you still need to run it in your
# console to load the gapminder data set, which is built into R by default.
data(Titanic)

# Convert the Titanic data to data frame format
Titanic <- Titanic %>% 
  as.data.frame()
```



#### a)

What demographic attributes can be used to describe each passenger before they boarded
the ship?


#### b)

Output tables that compare survivor counts

1. between men and women
1. between the different classes

```{r, echo=TRUE}
# Write your code below:

```



#### c)

For each comparison in part b), indicate who was most likely to survive.

