---
title: "Data Class Lab"
output: html_document
editor_options: 
  chunk_output_type: console
---

# Data used

Bike Lanes Dataset: BikeBaltimore is the Department of Transportation's bike program. 
The data is from http://data.baltimorecity.gov/Transportation/Bike-Lanes/xzfj-gyms

You can Download as a CSV in your current working directory.  Note its also available at: 	http://johnmuschelli.com/intro_to_r/data/Bike_Lanes.csv 

```{r}
library(readr)
library(tidyverse)
library(dplyr)
library(lubridate)
library(jhur)

bike = read_csv(
  "http://johnmuschelli.com/intro_to_r/data/Bike_Lanes.csv")
```


or use 
```{r}
library(jhur)
bike = read_bike()
```



# Part 1

1.  Get all the differet types of bike types from the `type` column.
 Use `sort(unique())`.  Assign this to an object `btypes`.  Remember the `pull` function can extract a single column from a data set (or `$`).
 
```{r q1}



```

2. Recode `type` as a factor that has the `SIDEPATH` level first.  Using `bike = bike %>% mutate(type = factor(type, levels = )`, where you paste in your levels. Print `head(bike$type)`.  Note what you see (quotation, levels, etc).  Run 
 `bike %>% count(type)` afterwards and note the order. Note the order of `table(bike$type)` as well.
 
```{r q2}
x = c("SIDEPATH","BIKE BOULEVARD", "BIKE LANE", "CONTRAFLOW",
        "SHARED BUS BIKE",  "SHARROW",  "SIGNED ROUTE")

```

3. Make a column `type2`, which is a factor of `type`, with the 
 levels (use `mutate`): 
 `type2 = factor(type, levels = c( "SIDEPATH", "BIKE BOULEVARD", "BIKE LANE"))` using `mutate`.  Run `table(bike$type2)`,
 with the option `useNA = "always"`, so the whole code is `table(bike$type2, useNA = "always")`.  Note, we do not have to make type a character again before doing this
```{r q3}


```

4. a) Reassign `dateInstalled` into a character using `as.character` using `bike %>% mutate(dateInstalled = )`, (fill in after the `=`).  Run `head(bike$dateInstalled)`.
```{r q4a}

```


 b) Reassign `dateInstalled` a factor, using the default levels (do NOT set `levels = ` ), `bike %>% mutate(dateInstalled = factor(XXXX))` (fill in `XXX`).  Run `head(bike$dateInstalled)`.
```{r q4b}



```

 c) Do not reassign `dateInstalled`, but simply run
 `head(as.numeric(bike$dateInstalled))` we are looking to see what happens when we try to go from factor to numeric
```{r q4c}

```


 d) Do not reassign `dateInstalled`, but simply run
 `head(as.numeric(as.character(bike$dateInstalled)))`
 this is how you get "numeric" values back if they were "incorrectly" 
 factors
```{r q4d}



```


# Part 2

5.  Convert `type` back to a character (using `as.character` and `mutate`).
 Make a column `type2` (replacing the old one, again `mutate`) where if the type is one of these categories:
 `c("CONTRAFLOW", "SHARED BUS BIKE", "SHARROW", "SIGNED ROUTE")`
 call it `"OTHER"`.  Use `%in%` and `ifelse`.  Make `type2` a factor
 with the levels `c( "SIDEPATH", "BIKE BOULEVARD", "BIKE LANE", "OTHER")`
```{r q5}

```

# Part 3

6.  Parse the following dates with the correct `lubridate` function:

a) "2014/02-14"

```{r q6a}

```

 b) "04/22/14 03:20"
 
```{r q6b}

```

c) "4/5/2016 03:2:22"  assume `mdy`

```{r q6c}

```










