m.names <- c("Baramgwa hamjje sarajida", "Sleepless in Seattle", "The Water Diviner",
"Fly Away Home", "The Three Musketeers", "Candyman: Farewell to Flesh",
"Honey I Blew Up the Kid", "Kingsman: The Secret Service", "Ajab Prem Ki Ghazab Kahani",
"A Bug's Life", "Courage Under Fire", "Dirty Pretty Things",
"In the Name of the Father", "Soul Plane", "Magnum Force", "About Time",
"House of Sand and Fog", "Bokura ga ita Zenpen", "Jackass 3D",
"Tropic Thunder - A Pirate's Tale")
boxoffice <- c(28686545, 218076024, 30864649, 35870837, 50375628, 13899536,
58662452, 404561724, 15906411, 363089431, 100748262, 14156753,
25096862, 14553807, 44680473, 89177486, 16157923, 26324268, 171685793,
191091250)
genre <- c("Action", "Romantic Comedy", "Drama", "Drama", "Adventure",
"Horror", "Comedy", "Action", "Comedy", "Adventure", "Drama",
"Drama", "Drama", "Comedy", "Action", "Romantic Comedy", "Drama",
"Drama", "Comedy", "Comedy")
time <- c(121, 100, 112, NA, NA, NA, NA, 129, NA, 96, 111, NA, NA, NA,
NA, 123, NA, 121, 93, 106)
rating <- c(NA, "PG", "R", "PG", "PG", "R", "PG", "R", NA, "G", "R",
"R", "R", "R", NA, "R", "R", NA, "R", "R")
Question 1
m.names [10]
## [1] "A Bug's Life"
Question 2
A
m.names.5 <- m.names[1:5]
m.names.5
## [1] "Baramgwa hamjje sarajida" "Sleepless in Seattle"
## [3] "The Water Diviner" "Fly Away Home"
## [5] "The Three Musketeers"
B
time[1:5]
## [1] 121 100 112 NA NA
Question 3
m.names[seq(2, length(boxoffice), by = 2)]
## [1] "Sleepless in Seattle" "Fly Away Home"
## [3] "Candyman: Farewell to Flesh" "Kingsman: The Secret Service"
## [5] "A Bug's Life" "Dirty Pretty Things"
## [7] "Soul Plane" "About Time"
## [9] "Bokura ga ita Zenpen" "Tropic Thunder - A Pirate's Tale"
Question 4
"Tropic Thunder" <- m.names[m.names == "Tropic Thunder - A Pirate's Tale"]
"Tropic Thunder"
## [1] "Tropic Thunder"
Question 5
"Romcom" <- genre[genre == "Romantic Comedy"]
"scarymovie!!!" <- genre[genre == "Horror"]
# For question 5 and 6 Not sure if this is the right way?
Question 6
boxoffice.millions <- boxoffice/1000000
Question 7
mean(boxoffice)
## [1] 95683306
median(boxoffice)
## [1] 40275655
sd(boxoffice)
## [1] 116422556
Question 8
table(genre)
## genre
## Action Adventure Comedy Drama
## 3 2 5 7
## Horror Romantic Comedy
## 1 2
Question 9
sum(genre == "Drama")
## [1] 7
Question 10
boxoffice[m.names == "A Bug's Life"]
## [1] 363089431
time[m.names == "A Bug's Life" ]
## [1] 96
rating[m.names =="A Bug's Life" ]
## [1] "G"
Question 11
"Pirates of the Caribbean" %in% m.names
## [1] FALSE
Question 12
m.names[genre == "Comedy"]
## [1] "Honey I Blew Up the Kid" "Ajab Prem Ki Ghazab Kahani"
## [3] "Soul Plane" "Jackass 3D"
## [5] "Tropic Thunder - A Pirate's Tale"
mean(boxoffice[genre == "Comedy"])
## [1] 90379943
Question 13
m.names[boxoffice >= 50000000]
## [1] "Sleepless in Seattle" "The Three Musketeers"
## [3] "Honey I Blew Up the Kid" "Kingsman: The Secret Service"
## [5] "A Bug's Life" "Courage Under Fire"
## [7] "About Time" "Jackass 3D"
## [9] "Tropic Thunder - A Pirate's Tale"
Question 14
A
min.boxoffice <- min(boxoffice[genre %in% c("Comedy", "Drama")])
min.boxoffice
## [1] 14156753
B
m.names[boxoffice == min.boxoffice]
## [1] "Dirty Pretty Things"
Question 15
A
median(time, na.rm = T)
## [1] 111.5
B
median(time, na.rm = T) / 60
## [1] 1.858333
Question 16
m.names[rating == "R"]
## [1] NA "The Water Diviner"
## [3] "Candyman: Farewell to Flesh" "Kingsman: The Secret Service"
## [5] NA "Courage Under Fire"
## [7] "Dirty Pretty Things" "In the Name of the Father"
## [9] "Soul Plane" NA
## [11] "About Time" "House of Sand and Fog"
## [13] NA "Jackass 3D"
## [15] "Tropic Thunder - A Pirate's Tale"
mean(boxoffice[rating == "R"], na.rm = T)
## [1] 97454004
Question 17
A
m.names[rating %in% c("G", "PG")]
## [1] "Sleepless in Seattle" "Fly Away Home"
## [3] "The Three Musketeers" "Honey I Blew Up the Kid"
## [5] "A Bug's Life"
B
mean(time[rating %in% c("G", "PG")], na.rm = T)
## [1] 98
Question 18
A
mean(genre == "Drama")
## [1] 0.35
B
mean(time > 100, na.rm = T)
## [1] 0.7
Question 19
m.names[boxoffice < 30000000 & genre == "Comedy"]
## [1] "Ajab Prem Ki Ghazab Kahani" "Soul Plane"
Question 20
boxoffice.order <- order(boxoffice, decreasing = F)
Question 21
m.names[boxoffice.order <= 5]
## [1] "Kingsman: The Secret Service" "Ajab Prem Ki Ghazab Kahani"
## [3] "A Bug's Life" "Dirty Pretty Things"
## [5] "Bokura ga ita Zenpen"
Question 22
mean(genre[boxoffice.order <= 10] == "Comedy")
## [1] 0.3
Question 23
boxoffice.true <- c(43101797, 57312618, 45018557, 43176378, 49664862, 54979733,
52483124, 61740438, 57291732, 53867028, 48131527, 42715635, 48903075,
46933555, 45086429, 43385326, 50106648, 44155883, 45193453, 39162775
)
boxoffice.true <- boxoffice
boxoffice
## [1] 28686545 218076024 30864649 35870837 50375628 13899536 58662452
## [8] 404561724 15906411 363089431 100748262 14156753 25096862 14553807
## [15] 44680473 89177486 16157923 26324268 171685793 191091250
# old codes
boxoffice.millions <- boxoffice/1000000
boxoffice.millions
## [1] 28.68654 218.07602 30.86465 35.87084 50.37563 13.89954 58.66245
## [8] 404.56172 15.90641 363.08943 100.74826 14.15675 25.09686 14.55381
## [15] 44.68047 89.17749 16.15792 26.32427 171.68579 191.09125
mean(boxoffice)
## [1] 95683306
median(boxoffice)
## [1] 40275655
sd(boxoffice)
## [1] 116422556
m.names[boxoffice >= 50000000]
## [1] "Sleepless in Seattle" "The Three Musketeers"
## [3] "Honey I Blew Up the Kid" "Kingsman: The Secret Service"
## [5] "A Bug's Life" "Courage Under Fire"
## [7] "About Time" "Jackass 3D"
## [9] "Tropic Thunder - A Pirate's Tale"
min.boxoffice <- min(boxoffice[genre %in% c("Comedy", "Drama")])
min.boxoffice
## [1] 14156753
m.names[boxoffice == min.boxoffice]
## [1] "Dirty Pretty Things"
mean(boxoffice[rating == "R"], na.rm = T)
## [1] 97454004
m.names[boxoffice < 30000000 & genre == "Comedy"]
## [1] "Ajab Prem Ki Ghazab Kahani" "Soul Plane"
boxoffice.order <- order(boxoffice, decreasing = F)
boxoffice.order
## [1] 6 12 14 9 17 13 18 1 3 4 15 5 7 16 11 19 20 2 10 8
m.names[boxoffice.order <= 5]
## [1] "Kingsman: The Secret Service" "Ajab Prem Ki Ghazab Kahani"
## [3] "A Bug's Life" "Dirty Pretty Things"
## [5] "Bokura ga ita Zenpen"
mean(genre[boxoffice.order <= 10] == "Comedy")
## [1] 0.3
Question 24
m.names.o <- m.names[boxoffice.order]
boxoffice.o <- boxoffice[boxoffice.order]
genre.o <- genre[boxoffice.order]
time.o <- time[boxoffice.order]
rating.o <- rating[boxoffice.order]
m.names.o
## [1] "Candyman: Farewell to Flesh" "Dirty Pretty Things"
## [3] "Soul Plane" "Ajab Prem Ki Ghazab Kahani"
## [5] "House of Sand and Fog" "In the Name of the Father"
## [7] "Bokura ga ita Zenpen" "Baramgwa hamjje sarajida"
## [9] "The Water Diviner" "Fly Away Home"
## [11] "Magnum Force" "The Three Musketeers"
## [13] "Honey I Blew Up the Kid" "About Time"
## [15] "Courage Under Fire" "Jackass 3D"
## [17] "Tropic Thunder - A Pirate's Tale" "Sleepless in Seattle"
## [19] "A Bug's Life" "Kingsman: The Secret Service"
boxoffice.o
## [1] 13899536 14156753 14553807 15906411 16157923 25096862 26324268
## [8] 28686545 30864649 35870837 44680473 50375628 58662452 89177486
## [15] 100748262 171685793 191091250 218076024 363089431 404561724
genre.o
## [1] "Horror" "Drama" "Comedy"
## [4] "Comedy" "Drama" "Drama"
## [7] "Drama" "Action" "Drama"
## [10] "Drama" "Action" "Adventure"
## [13] "Comedy" "Romantic Comedy" "Drama"
## [16] "Comedy" "Comedy" "Romantic Comedy"
## [19] "Adventure" "Action"
time.o
## [1] NA NA NA NA NA NA 121 121 112 NA NA NA NA 123 111 93 106
## [18] 100 96 129
rating.o
## [1] "R" "R" "R" NA "R" "R" NA NA "R" "PG" NA "PG" "PG" "R"
## [15] "R" "R" "R" "PG" "G" "R"