--- title: 'Laboratory Exercise Week 1' author: "Your Name and Section" date: "Todays Date" output: word_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` *Directions*: * Write your R code inside the code chunks after each question. * Write your answer comments after the `#` sign. * To generate the word document output, click the button `Knit` and wait for the word document to appear. * RStudio will prompt you (only once) to install the `knitr` package. * Submit your completed laboratory exercise using Blackboard's Turnitin feature. Your Turnitin upload link is found on your Blackboard Course shell under the Laboratory folder. *** 1. Create a vector of three elements `(2,4,6)` and name that vector `vec.a`. Create a second vector, `vec.b`, that contains `(8,10,12)`. a. Add these two vectors together and name the result `vec.c`. b. Create a vector, named `vec.d`, that contains only two elements `(14,20)`. Add this vector to `vec.a`. What is the result and what do you think `R` did (look up the recycling rule using `Google`)? What is the warning message that `R` gives you? c. Next add 5 to the vector `vec.a`. What is the result and what did `R` do? Why doesn’t it give you a warning message similar to what you saw in the previous problem? ## Code chunk ```{r} # Insert your code for this question after this line trial.vec <- 1:20 trial.vec # last R code line ``` 2. Generate the vector of even numbers `{2, 4, 6, . . . , 20}` a. Using the `seq()` function and b. Using the `a:b` shortcut and some subsequent algebra. *Hint: Generate the vector 1-10 and then multiple it by 2.* ```{r} # Insert your code for this question after this line ``` 3. Create a vector `y` containing `(2, 2, 2, 2, 4, 4, 4, 4, 8, 8, 8, 8)` using the `rep()` function. You might need to check the help file for `rep()` by typing `?rep` in the console to see all of the options that `rep()` will accept. In particular, look at the optional argument `each=`. a. Find the mean of vector `y` using the function `mean()`. b. Use google search to find the function in `R` that computes the variance of a vector and find the variance of `y`. ```{r} # Insert your code for this question after this line ``` 4. The vector `letters` is a built-in vector to `R` and contains the lower case English alphabet. a. Extract the 9th element of the `letters` vector. b. Extract the sub-vector that contains the 9th, 11th, and 19th elements. c. Extract the sub-vector that contains everything except the last two elements. ```{r} # Insert your code for this question after this line ```