`R`

Basics**Lab Goal:** The simple goal of this lab is to get you thinking about `R`

and RStudio again.

This lab can be completed with only `R`

and without RStudio, but you should really use RStudio. For reference material, see Applied Statistics with `R`

chapter two through six.

**[Exercise]** Calculate \(e^2\).

**[Exercise]** Calculate the natural log of 3.

`y = c(0, 2, NA, 3, 4, 1, 9, 0)`

**[Exercise]** Calculate the mean of `y`

with the missing values removed. Use **only** the `mean()`

function.

- Hint 1: Check the documentation for
`mean()`

. - Hint 2: If youâ€™re really stuck, there always this approach.

**[Exercise]** Run the following code:

```
ggplot(mpg, aes(x = reorder(class, hwy), y = hwy, fill = class)) +
geom_boxplot() +
xlab("class") +
theme(legend.position = "none")
```

To do so, you will need to make sure the `ggplot2`

package is installed, and loaded.

**[Exercise]** Modify the following code to run, but without loading the entire `MASS`

library. The `lda()`

function is from the `MASS`

package.

`lda(Species ~ ., data = iris)$means`

`x = 1:100`

**[Exercise]** Calculate

\[ \sum_{i = 1}^{n} \ln(x_i). \]

That is, sum the log of each element of `x`

.

**[Exercise]** After running the following code, how many of the elements of `some_vector`

are larger than `1`

? A good solution will use only one line of code.

```
set.seed(42)
some_vector = rnorm(100)
```

**[Exercise]** Consider a random variable \(X\) that has a normal distribution with a mean of 5 and a variance of 9. Calculate

\[ P[X > c], \]

for \(c = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.\)