Creating a new list for another movie
You found reviews of another, more recent, Jack Nicholson movie: The Departed!
Scores | Comments |
---|---|
4.6 | I would watch it again |
5 | Amazing! |
4.8 | I liked it |
5 | One of the best movies |
4.2 | Fascinating plot |
It would be useful to collect together all the pieces of information about the movie, like the title, actors, and reviews into a single variable. Since these pieces of data are different shapes, it is natural to combine them in a list variable.
movie_title
, containing the title of the movie, and movie_actors
, containing the names of some of the actors in the movie, are available in your workspace.
This exercise is part of the course
Introduction to R
Exercise instructions
- Create two vectors, called
scores
andcomments
, that contain the information from the reviews shown in the table. - Find the average of the
scores
vector and save it asavg_review
. - Combine the
scores
andcomments
vectors into a data frame calledreviews_df
. - Create a list, called
departed_list
, that contains themovie_title
,movie_actors
, reviews data frame asreviews_df
, and the average review score asavg_review
, and print it out.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Use the table from the exercise to define the comments and scores vectors
scores <- c(4.6, 5, 4.8, 5, ___
comments <- c("I would watch it again", "Amazing!", "I liked it", "One of the best movies", ___
# Save the average of the scores vector as avg_review
# Combine scores and comments into the reviews_df data frame
# Create and print out a list, called departed_list