18.4 Chapter 7: Indexing vectors with []
movie | year | boxoffice | genre | time | rating |
---|---|---|---|---|---|
Whatever Works | 2009 | 35.0 | Comedy | 92 | PG-13 |
It Follows | 2015 | 15.0 | Horror | 97 | R |
Love and Mercy | 2015 | 15.0 | Drama | 120 | R |
The Goonies | 1985 | 62.0 | Adventure | 90 | PG |
Jiro Dreams of Sushi | 2012 | 3.0 | Documentary | 81 | G |
There Will be Blood | 2007 | 10.0 | Drama | 158 | R |
Moon | 2009 | 321.0 | Science Fiction | 97 | R |
Spice World | 1988 | 79.0 | Comedy | -84 | PG-13 |
Serenity | 2005 | 39.0 | Science Fiction | 119 | PG-13 |
Finding Vivian Maier | 2014 | 1.5 | Documentary | 84 | Unrated |
- Create new data vectors for each column.
movie <- c("Whatever Works", "It Follows", "Love and Mercy",
"The Goonies", "Jiro Dreams of Sushi",
"There Will be Blood", "Moon",
"Spice World", "Serenity", "Finding Vivian Maier")
year <- c(2009, 2015, 2015, 1985, 2012, 2007, 2009, 1988, 2005, 2014)
boxoffice <- c(35, 15, 15, 62, 3, 10, 321, 79, 39, 1.5)
genre <- c("Comedy", "Horror", "Drama", "Adventure", "Documentary",
"Drama", "Science Fiction", "Comedy", "Science Fiction",
"Documentary")
time <- c(92, 97, 120, 90, 81, 158, 97, -84, 119, 84)
rating <- c("PG-13", "R", "R", "PG", "G", "R", "R",
"PG-13", "PG-13", "Unrated")
- What is the name of the 10th movie in the list?
- What are the genres of the first 4 movies?
- Some joker put Spice World in the movie names – it should be ``The Naked Gun’’ Please correct the name.
- What were the names of the movies made before 1990?
- How many movies were Dramas? What percent of the 10 movies were Comedies?
- One of the values in the
time
vector is invalid. Convert any invalid values in this vector to NA. Then, calculate the mean movie time
- What were the names of the Comedy movies? What were their boxoffice totals? (Two separate questions)
- What were the names of the movies that made less than $50 Million dollars AND were Comedies?
- What was the median boxoffice revenue of movies rated either G or PG?
- What percent of the movies were either rated R OR were comedies?