library(dplyr) library(readr)

Load the movies dataset

movies <- read_csv(“https://gist.githubusercontent.com/tiangechen/b68782efa49a16edaf07dc2cdaa855ea/raw/0c794a9717f18b094eabab2cd6a6b9a226903577/movies.csv”)

1. Rename columns

movies_renamed <- movies %>% rename(movie_title = Film, release_year = Year)

# A tibble: 6 × 8 movie_title Genre Lead Studio Audience score % Profitability 1 Zack and Miri Make… Roma… The Weinstei… 70 1.75 2 Youth in Revolt Come… The Weinstei… 52 1.09 3 You Will Meet a Ta… Come… Independent 35 1.21 4 When in Rome Come… Disney 44 0
5 What Happens in Ve… Come… Fox 72 6.27 6 Water For Elephants Drama 20th Century… 72 3.08

Show the first 6 rows of data

head(movies_renamed)

2. Select specific columns

movies_selected <- movies_renamed %>% select(movie_title, release_year, Genre, Profitability)

Show the first 6 rows of data

head(movies_selected)

3. Filter movies released after 2000 with Rotten Tomatoes % > 80

movies_filtered <- movies_renamed %>% filter(release_year > 2000, Rotten Tomatoes % > 80)

Show the first 6 rows of data

head(movies_filtered)

4. Add a column that converts Profitability to millions

movies_mutated <- movies_filtered %>% mutate(Profitability_millions = Profitability / 1e6)

Show the first 6 rows of data

head(movies_mutated)

5. Sort the dataset by Rotten Tomatoes % and Profitability in descending order

movies_sorted <- movies_mutated %>% arrange(desc(Rotten Tomatoes %), desc(Profitability_millions))

Show the first 6 rows of data

head(movies_sorted)

6. Combining all operations in one chain

movies_combined <- 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 / 1e6) %>% arrange(desc(Rotten Tomatoes %), desc(Profitability_millions))

Show the first 6 rows of data

head(movies_combined)