---
title: "Lesson 05 - Working with Data (notes)"
output: html_document
---

This notes file is a place for you to practice writing and executing the code found in the lecture notes. This is also a spot where you can (and should) write your own notes and thoughts. Explain what you are doing in each code chunk in your own words. 


## Preparation
Before class, run the following code chunk to make sure it works. 
If it does not, try to understand what the error message is telling you. Refer to the [FAQ page](https://norcalbiostat.github.io/MATH130/faq.html) for assistance. 

```{r}
library(dplyr)
ncbirths <- openintro::ncbirths
```

----- 

# Missing Data

## Problems


## Identifying missing values 


----

# Summarizing data


## Frequency Tables for categorical data
Create a frequency table for whether or not the baby was born underweight. 

```{r}
 
```

Do it again but show if there are any missing. 

```{r}
 
```

## Summary statistics for numerical data

Summary statistics for the number of visits. 

```{r}

```

-----

# Data editing (recoding)



**Example 1: Too low birthweight**

Set all records where `weight=1` to missing. 

```{r}
 
```

Confirm it worked by creating a boxplot of `weight`. 
```{r}

```

-----

# Creating new variables


#### **Example: basic arithmetic on existing variables**


Create a new variable `wtgain_mom` the weight gained by the mother, that is not due to the baby by subtracting `weight` from `gained`.
```{r}
 
```

Confirm this variable was created correctly

```{r}

```



## Dichtomizing data 

Make a new variable `underage` on the `NCbirths` data set. If `mage` is under 18, then the value of this new variable is `underage`, else it is labeled as `adult`. 

```{r}

```

Confirm it worked.

```{r}
 
```


# Chaining using the pipe %>%

```{r}

```


