---
title: "Lab 2 Solutions"
author: "Alexandra Chouldechova"
output: html_document
---

```{r}
library(tidyverse)
```

#### 1. Changing the author field and file name.

##### (a) Change the `author:` field on the Rmd document from Your Name Here to your own name.

##### (b) Rename this file to "lab02_YourHameHere.Rmd", where YourNameHere is changed to your own name.

#### 2. Data practice

In class we imported the survey data using the `read.table()` function.  (Note: on Homework 1 you'll be asked to use the `read.csv()` function instead.)

This is the code we used:

```{r}
survey <- read.table("http://www.andrew.cmu.edu/user/achoulde/94842/data/survey_data2020.csv", header=TRUE, sep=",") 
```

##### (a) How many survey respondents are from MISM or Other?

```{r}
sum(survey[["Program"]] == "MISM" | survey[["Program"]] == "Other")
```

##### (b) What % of survey respondents are from PPM?

```{r}
100 * sum(survey[["Program"]] == "PPM") / nrow(survey)
```

#### 3. Index practice

##### (a) Use $ notation to pull the OperatingSystem column from the survey data

```{r}
survey$OperatingSystem
```

##### (b) Do the same thing with [,] notation, referring to OperatingSystem by name

```{r}
survey[, "OperatingSystem"]
```

##### (c) Repeat part (b), this time referring to OperatingSystem by column number

```{r}
survey[, 4]
```

##### (d) Repeat part (b), this time using the `select()` function.

```{r}
select(survey, OperatingSystem)
```

##### (e) Use `filter()` and `select()` together to get the `Program` and `Rexperience` of every student who watched at least 10 hours of TV last week.

```{r}
survey %>%
  filter(TVhours >= 10) %>%
  select(Program, Rexperience)
```

#### 4. Optional practice

Try re-running as much of the lecture code as you have time for, taking time to understand what is happening in each line of code.  You can enter the code directly into the Console.  (Optional: you may enter your code in the code chunk below.)

**Tip:** Instead of copying and pasting code, practice typing it yourself.  This will help you to learn the syntax.

```{r}
# Edit me (optional)
```
