library(dplyr)
rename(): (4 points) Rename the “Film” column to “movie_title” and “Year” to “release_year”. # (Optional) Check the first 6 rows of the ORIGINAL dataset head(movies, 6) one <- movies %>% rename( movie_title = Film, release_year = Year )
select(): (4 points) Create a new dataframe with only the columns: movie_title, release_year, Genre, Profitability, head(one, 6) two <- one %>% select(movie_title, release_year, Genre, Profitability)
filter(): (4 points) Filter the dataset to include only movies
released after 2000 with a Rotten Tomatoes % higher than 80. head(two,
6) three <- one %>% select(movie_title, release_year, Genre,
Profitability, Rotten Tomatoes %) %>%
filter(release_year > 2000, Rotten Tomatoes % >
80)
mutate(): (4 points) Add a new column called “Profitability_millions” that converts the Profitability to millions of dollars. head(three, 6) four <- three %>% mutate(Profitability_millions = Profitability / 1000000)
arrange(): (3 points) Sort the filtered dataset by Rotten
Tomatoes % in descending order, and then by Profitability in descending
order. five <- four %>% arrange(desc(Rotten Tomatoes %) ,
desc(Profitability_millions)) head(four, 6) five <- four %>%
arrange(desc(Rotten Tomatoes %),
desc(Profitability_millions))
Combining functions: (3 points) Use the pipe operator (%>%) to
chain these operations together, starting with the original dataset and
ending with a final dataframe that incorporates all the above
transformations. head(five, 6) six <- movies %>% rename(
movie_title = Film, release_year = Year ) %>% select(movie_title,
release_year, Genre, Profitability, Rotten Tomatoes %)
%>% filter(release_year > 2000, Rotten Tomatoes %
> 80) %>% mutate(Profitability_millions = Profitability / 1000000)
%>% arrange(desc(Rotten Tomatoes %),
desc(Profitability_millions)) head(six, 6)
Interpret question 6 (1 point) From the resulting data, are the best movies the most popular? # From the resulting data, the best movies are not always the most popular. While all movies in the dataset have high Rotten Tomatoes scores (above 80%), their profitability varies widely. For example, some highly rated films like WALL-E and Midnight in Paris are both critically acclaimed and profitable, but other well-reviewed movies such as Jane Eyre or My Week with Marilyn have much lower profitability. This suggests that strong critical reception does not necessarily guarantee high popularity or financial success.