# LAB: Lists

This is the lab associated with the lecture and lesson on Lists in R.

Please upload your final completed lab on the Assignments page in Canvas, as per the instructions below.

You are welcome and expected to ask for help from the instructors if you get stuck: Please also come to the R Bootcamp on Friday—there is coffee and snacks!

## A. Function output as lists

The output of many functions, especially statistical tests, is a list.

Run a t-test on two vectors (we will cover statistial tests after October break, so don’t worry about the details now). We have assigned it to a new object ‘m’.

``````m <- t.test(1:10, 10:1)
``````
1. Is it a list? Check with is.list()

2. Look at the structure of ‘m’.

3. Extract the p-value

4. Extract the estimated mean of x.

## B. Harry Potter Movies (surprise!)

Think back to the lab on Vectors …

1. Create an object containing the text string “Harry Potter and the”. Call this string `hpat`.

2. Create a vector with the specific title section for each movie 1–8 (e.g., “Sorcerer’s Stone” for movie 1), called `hp_titles`.

3. Combine the vectors `hpat` and `hp_titles` to create a vector of 8 elements for the full titles of the first 8 movies. Call this vector `hp_movies`

4. Put these three objects into a list.

5. Read in the Harry Potter Movie data

``````dat_hp <- read.table("http://www.simonqueenborough.info/R/data/harry-potter-movies-numeric.txt",
sep = '\t', header = TRUE)
``````
1. Is there a statistical difference between the worldwide box office returns for Harry Potter movies made before 2005 and those made after? Pull out the model estimates and associated p value. (hint: You can subset and then use the t.test like above).