---
title: "Exercise 1: Introduction to R SOLUTIONS"
author: "Rian DeFaccio, for BH Analytics LLC"
date: "`r Sys.Date()`"
output: html_document
---

This exercise builds on the concepts introduced in the notebook "Introduction to R".

**Question 1:** Check your working directory.

```{r}
getwd()
```

**Question 2:** We are going to setup a code chunk that converts Celsius to degrees Fahrenheit.

1.  Save a variable that represents 15 degrees Celsius.
2.  Use that variable in the following equation to convert to degrees Fahrenheit: $(degrees_C *9/5)+32$
3.  Update your degrees Celsius variable to a new value of your choice.
4.  Recalculate the degrees Fahrenheit.

```{r}
# save 15 degrees C
deg_c <- 15

# convert 15C to F
(deg_c * 9 / 5) + 32

# pick a new degrees C
deg_c <- 0

# recalculate conversion
(deg_c * 9 / 5) + 32
```

**Question 3:** Lets explore our R session a little.

1.  List all of the objects currently in your R session.
2.  Remove the last object that shows up on the previous list.
3.  Update the list of objects in your session to see if the remove command worked.

```{r}
# list all objects
ls()

# remove last object
rm(deg_c)

# check again
ls()
```

**Question 4:** Lets now explore the help/documentation for a single function.

1.  Call the help for the base R function `dir()`. You can call help using `?` or `help()`. The help will pop up on the **Help** pane of RStudio.

2.  What are the main headings in the help file?

    **Description, Usage, Arguments, Value, Note, Author(s), See Also, Examples**

3.  Can you describe what this function does?

    **This function lists all files and folders in the specified directory/folder.**

4.  Which section header describes the output of the function? What is the output of this function?

    **"Value" describes the output. The output in this case is a listing of all files and folders.**

5.  Which section lists the default values for arguments to the function?

    **Usage**

```{r}
?dir
```

6.  Now use this function to learn something about our course materials.

```{r}
dir()
```

7.  Now use this function to learn about items on your desktop.

```{r}
dir("../../..") # just moving up 3 levels
```

**Question 5:** Find another base R function that you would like to learn about and explore its documentation. See a full list of base R functions at this URL: <https://statisticsglobe.com/r-functions-list/>

*HInt:* A good way to try to understand new functions is to copy and paste from the *Examples* section.

```{r}
#### there are many functions to look up!
# let's look at seq()
seq(from = 1, to = 10, by = 2)

# try another way
seq(from = 1, length.out = 10, by = 2)
```
