library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Dataset
movies <- read.csv("https://gist.githubusercontent.com/tiangechen/b68782efa49a16edaf07dc2cdaa855ea/raw/0c794a9717f18b094eabab2cd6a6b9a226903577/movies.csv")
Question 1 - Rename
Renamed_movies <- movies %>%
rename(movie_title = Film, release_year = Year)
Question 2 - Select
Select_movies <- Renamed_movies %>%
select(movie_title, release_year, Genre, Profitability)
print(head(Select_movies))
## movie_title release_year Genre Profitability
## 1 Zack and Miri Make a Porno 2008 Romance 1.747542
## 2 Youth in Revolt 2010 Comedy 1.090000
## 3 You Will Meet a Tall Dark Stranger 2010 Comedy 1.211818
## 4 When in Rome 2010 Comedy 0.000000
## 5 What Happens in Vegas 2008 Comedy 6.267647
## 6 Water For Elephants 2011 Drama 3.081421
Question 3 - Filter
Filter_movies <- Renamed_movies %>%
filter(release_year > 2000 & Rotten.Tomatoes..>80)
print(Filter_movies)
## movie_title Genre Lead.Studio Audience.score..
## 1 WALL-E Animation Disney 89
## 2 Waitress Romance Independent 67
## 3 Tangled Animation Disney 88
## 4 Rachel Getting Married Drama Independent 61
## 5 My Week with Marilyn Drama The Weinstein Company 84
## 6 Midnight in Paris Romence Sony 84
## 7 Knocked Up Comedy Universal 83
## 8 Jane Eyre Romance Universal 77
## 9 Enchanted Comedy Disney 80
## 10 Beginners Comedy Independent 80
## 11 A Serious Man Drama Universal 64
## 12 (500) Days of Summer comedy Fox 81
## Profitability Rotten.Tomatoes.. Worldwide.Gross release_year
## 1 2.896019 96 $521.28 2008
## 2 11.089742 89 $22.18 2007
## 3 1.365692 89 $355.01 2010
## 4 1.384167 85 $16.61 2008
## 5 0.825800 83 $8.26 2011
## 6 8.744706 93 $148.66 2011
## 7 6.636402 91 $219 2007
## 8 0.000000 85 $30.15 2011
## 9 4.005737 93 $340.49 2007
## 10 4.471875 84 $14.31 2011
## 11 4.382857 89 $30.68 2009
## 12 8.096000 87 $60.72 2009
Question 4 - Mutate
Mutate_movies <- Filter_movies %>%
mutate(Profitability_in_Millions = Profitability*1000000)
print(select(Mutate_movies, Profitability_in_Millions))
## Profitability_in_Millions
## 1 2896019
## 2 11089742
## 3 1365692
## 4 1384167
## 5 825800
## 6 8744706
## 7 6636402
## 8 0
## 9 4005737
## 10 4471875
## 11 4382857
## 12 8096000
Question 5 - Arrange
sorted_movies <- Mutate_movies %>%
arrange(desc(Rotten.Tomatoes..), desc(Profitability_in_Millions))
print(select(sorted_movies, Rotten.Tomatoes.., Profitability_in_Millions))
## Rotten.Tomatoes.. Profitability_in_Millions
## 1 96 2896019
## 2 93 8744706
## 3 93 4005737
## 4 91 6636402
## 5 89 11089742
## 6 89 4382857
## 7 89 1365692
## 8 87 8096000
## 9 85 1384167
## 10 85 0
## 11 84 4471875
## 12 83 825800
Question 6 - Combine
Combine_Movies <- 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_in_Millions = Profitability*1000000) %>%
arrange(desc(Rotten.Tomatoes..), desc(Profitability_in_Millions))
print(head(Combine_Movies))
## movie_title release_year Genre Profitability Rotten.Tomatoes..
## 1 WALL-E 2008 Animation 2.896019 96
## 2 Midnight in Paris 2011 Romence 8.744706 93
## 3 Enchanted 2007 Comedy 4.005737 93
## 4 Knocked Up 2007 Comedy 6.636402 91
## 5 Waitress 2007 Romance 11.089742 89
## 6 A Serious Man 2009 Drama 4.382857 89
## Profitability_in_Millions
## 1 2896019
## 2 8744706
## 3 4005737
## 4 6636402
## 5 11089742
## 6 4382857
Question 7 - Interpert
# The highest rated movies are not always the most profitable as shown in the data.