# Part 1

### 1.1

Load all the packages we will use in this lab. 

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

Create some data to work with by running the following code chunk.

```{r}
set.seed(1234)

int_vect <- rep(seq(from = 1, to = 10), times = 3)
rand_vect <- sample(x = 1:30, size = 30, replace = TRUE)
TF_vect <- rep(c(TRUE, TRUE, FALSE), times = 10)
TF_vect2 <- rep(c("TRUE", "TRUE", "FALSE"), times = 10)
```

### 1.2

Determine the class of each of these new objects.

```{r 1.2response}
class(int_vect) # [1] "integer"
class(rand_vect) # [1] "integer"
class(TF_vect) # [1] "logical"
class(TF_vect2) # [1] "character"
```

### 1.3

Are `TF_vect` and `TF_vect2` different classes? Why or why not?

```{r 1.3response}
# Yes!
# Logical vectors do not have quotes around `TRUE` and `FALSE` values.
```

### 1.4

Create a tibble combining these vectors together called `vect_data` using the following code.

```{r}
vect_data <- tibble(int_vect, rand_vect, TF_vect, TF_vect2)
```

### 1.5

Coerce `rand_vect` to character class using `as.character()`. Save this vector as `rand_char_vect`. How is the output for `rand_vect` and `rand_char_vect` different?

```{r 1.5response}
rand_char_vect <- as.character(rand_vect)
rand_char_vect # Numbers now have quotation marks
```

### 1.6

Read in the National Wastewater Surveillance System (NWSS) SARS-CoV-2 Wastewater data from `dasehr` package using the code supplied in the chunk. Alternatively using the url link. 

The NWSS uses water from different sewage treatment plants to test for covid, as a way to estimate how many covid infections a community is experiencing.

```{r}
covidww <- covid_wastewater
# covidww <- read_csv(file = "https://daseh.org/data/SARS-CoV-2_Wastewater_Data.csv")
```

### 1.7

Use the `mutate()` function to create a new column named `date_formatted` that is of `first_sample_date` class. The new variable is created from `date` column. Hint: use `mdy()` function. Reassign to `covidww`.

```
# General format
NEWDATA <- OLD_DATA %>% mutate(NEW_COLUMN = OLD_COLUMN)
```

```{r 1.7response}
covidww <- covidww %>% mutate(date_formatted = mdy(first_sample_date))
```


# Practice on Your Own!

### P.1

Move the `date_formatted` variable to be before `first_sample_date` using the `relocate` function. Take a look at the data using `glimpse()`. Note the difference between `first_sample_date` and `date_formatted` columns.

```
# General format
NEWDATA <- OLD_DATA %>% relocate(COLUMN1, .before = COLUMN2)
```

```{r P.1response}
covidww <- covidww %>% relocate(date_formatted, .before = first_sample_date)

# alternative
# covidww <- covidww %>% select(first_sample_date, date_formatted, everything()) %>% head() 

glimpse(covidww)

```

### P.2

Use `range()` function on `date_formatted` variable to display the range of dates in the data set. How does this compare to that of `first_sample_date`? Why? (Hint: use the pull function first to pull the values.)

```{r P.2response}
pull(covidww, date_formatted) %>% range()
pull(covidww, first_sample_date) %>% range()

# The max of `pull(covidww, first_sample_date) %>% range()` is numerical not based on date.
```
