FES 720 Introduction to R

LAB: Subsetting Vectors

This is the lab associated with the lecture and lesson on Subsetting Vectors 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!

In this lab, we will continue to work with data from the Harry Potter series of moving pictures.

Use the three vectors from last time.

year <- c(2001, 2002, 2004, 2005, 2007, 2009, 2010, 2011, 2016)

prod_budget <- c(125000000, NA, 130000000, 150000000, NA, 250000000, 125000000, 125000000, 180000000)

ww_boxoffice <- c(974755371, 878979634, NA, 896911078, NA, 935083686, 960283305, 1341511219, 803798342)


  1. Using the vector year, create an object of all the years with films after 2005.

  2. Subset prod_budget to create a vector of production budgets without any missing data.

  3. Subset this new vector to contain all values greater or equal to 150,000,000.

  4. Subset ww_boxoffice to create a vector with no missing data.

  5. Subset this vector to create a new vector of values less than 900,000,000.

  6. Remove the second element from this new vector.

  7. Add the correct film title epithet (e.g., “Sorcerer’s Stone”) as names for the remaining elements in this vector.

  8. Subset one of them by name.

How to write up your answers

Please check the help page for a reminder, if you need to.

Updated: 2017-09-25