# Activity 09/03/2021 ## STAT 445 / 645 -- Section 1001
Instructor: Colin Grudzien
## Instructions: We will work through the following series of activities as a group. Follow the instructions in each sub-section when the instructor assigns you to a breakout room. ## Activities: ### Activity 1: Vectorization #### Question 1: Given the following matrix: ```{r eval=FALSE} m <- matrix(1:12, nrow=3, ncol=4) m ``` What you think will happen when you run each of the following? 1. `m ^ -1` 2. `m * c(1, 0, -1)` 3. `m > c(0, 20)` 4. `m * c(1, 0, -1, 2)` Did you get the output you expected? #### Question 2: We're interested in looking at the sum of the following sequence of fractions: ```{r, eval=FALSE} x = 1/(1^2) + 1/(2^2) + 1/(3^2) + ... + 1/(n^2) ``` This would be tedious to type out, and impossible for high values of n. Use vectorisation to compute x when n=100. What is the sum when n=10,000? #### Question 3: Make a vector with the numbers 1 through 26. Multiply the vector by 2, and give the resulting vector elements the names A through Z (hint: there is a built in vector called `LETTERS`). ### Activity 2: More on list subsetting #### Question 1: Given the following list: ```{r eval=FALSE} xlist <- list(a = "Software Carpentry", b = 1:10, data = head(iris)) ``` Using your knowledge of both list and vector subsetting, extract the number 2 from xlist. Hint: the number 2 is contained within the "b" item in the list. ### Activity 3: Open work on plotting with Gapminder We will take this time to work on the plotting exercise with Gapminder from earlier in the week. If you have questions, please feel free to ask.