---
title: "Exercise: Why R For Data Science?"
author: "Rian DeFaccio, for BH Analytics LLC"
date: "`r Sys.Date()`"
output: html_document
---

This exercise will reinforce concepts previously learned about creating and interacting with basic R data structures.

## Infant Data

The following table describes birth weights for infants born of mothers who smoke.

| row | birth weight (oz.) | sex | smoke \* |
|-----|--------------------|-----|----------|
| 1   | 81                 | f   | 0        |
| 2   | 95                 | f   | 0        |
| 3   | 109                | f   | 0        |
| 4   | 117                | f   | 1        |
| 5   | 123                | f   | 1        |
| 6   | 100                | m   | 1        |
| 7   | 114                | m   | 0        |
| 8   | 118                | m   | 1        |
| 9   | 119                | m   | 0        |
| 10  | 126                | m   | 0        |
| 11  | 140                | m   | 1        |

: \* mother who smoke: smoke = 1; who don't smoke: smoke = 0.

We have created 3 vector variables called `birthweight`, `sex`, and `smoke` with the values from the table above.

```{r}
birthweight <- c(81,95,109,117,123,100,114,118,119,126,140)
sex         <- c("f","f","f","f","f","m","m","m","m","m","m")
smoke       <- c(0,0,0,1,1,1,0,1,0,0,1)
```

### Question 1 

Create a logical vector that indicates which are female babies. Call your new variable `females`.

```{r}

```

### Question 2 

Print your vector `females` to the screen.

```{r}

```

### Question 3

Select the birth weights of female babies using your logical vector. Use the `birthweight[females]` pattern. Inspect the resulting values and answer:

1.  What is the lowest birth weight value for female babies?
2.  What is the highest birth weight value for female babies?
3.  What is the mean birth weight for female babies?

```{r}

```

### Question 4

Get a vector of birth weights that has been standardized. To get a standardized vector, subtract each birth weight by the mean of all birth weights and divide by the standard deviation of all birth weights.

1.  Save this vector as `weights_std`. *Hint:* you will use a vectorized calculation here.

```{r}

```

2.  Check the mean and standard deviation of your new, standardized vector of weights.

```{r}

```

### Question 5

Combine all of the vectors you have created so far into a data frame called `df_birthweight`. Print it to the screen.

```{r}

```

### Question 6

Practice sub-setting your new data frame. In each case, also note what type of R object is the result.

1.  Get the first row, first column.

```{r}

```

2.  Get the entire first row.

```{r}

```

3.  Get the entire first column. We know of two ways to do this so far.

```{r}

```

4.  Get the first two rows, and the first two columns. There are at least two ways to do this.

```{r}

```

5.  Get rows where the birth weight is less than 100 with all columns.

```{r}

```

### Question 7

Add a new column to the birth weight data frame called `under_weight` which is `TRUE` if a baby weighs less than 105 oz. and `FALSE` otherwise. Print the full data frame to the screen after you finish

```{r}

```
