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
movie.name <- m.names[10]
movie.name
## [1] "A Bug's Life"
Question 2
genre5 <- genre[1:5]
genre5
## [1] "Action" "Romantic Comedy" "Drama" "Drama"
## [5] "Adventure"
time5 <- time[1:5]
time5
## [1] 121 100 112 NA NA
Question 3
every.second <- m.names[seq(2, length(m.names), by = 2)]
every.second
## [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
where.is <- m.names %in% "Tropic Thunder - A Pirate's Tale"
where.is
## [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [12] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE
m.names[20] <- "Tropic Thunder"
m.names
## [1] "Baramgwa hamjje sarajida" "Sleepless in Seattle"
## [3] "The Water Diviner" "Fly Away Home"
## [5] "The Three Musketeers" "Candyman: Farewell to Flesh"
## [7] "Honey I Blew Up the Kid" "Kingsman: The Secret Service"
## [9] "Ajab Prem Ki Ghazab Kahani" "A Bug's Life"
## [11] "Courage Under Fire" "Dirty Pretty Things"
## [13] "In the Name of the Father" "Soul Plane"
## [15] "Magnum Force" "About Time"
## [17] "House of Sand and Fog" "Bokura ga ita Zenpen"
## [19] "Jackass 3D" "Tropic Thunder"
Question 5
whereisthelove <- genre %in% "Romantic Comedy"
whereisthelove
## [1] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [12] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
genre[whereisthelove] <- "RomCom"
genre
## [1] "Action" "RomCom" "Drama" "Drama" "Adventure"
## [6] "Horror" "Comedy" "Action" "Comedy" "Adventure"
## [11] "Drama" "Drama" "Drama" "Comedy" "Action"
## [16] "RomCom" "Drama" "Drama" "Comedy" "Comedy"
buhoo <- genre %in% "Horror"
genre[buhoo] <- "Scary movie!!!"
genre
## [1] "Action" "RomCom" "Drama" "Drama"
## [5] "Adventure" "Scary movie!!!" "Comedy" "Action"
## [9] "Comedy" "Adventure" "Drama" "Drama"
## [13] "Drama" "Comedy" "Action" "RomCom"
## [17] "Drama" "Drama" "Comedy" "Comedy"
Question 6
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
Question 7
mean(boxoffice.millions)
## [1] 95.68331
median(boxoffice.millions)
## [1] 40.27566
sd(boxoffice.millions)
## [1] 116.4226
mean(boxoffice)
## [1] 95683306
median(boxoffice)
## [1] 40275655
sd(boxoffice)
## [1] 116422556
Question 8
table(genre)
## genre
## Action Adventure Comedy Drama RomCom
## 3 2 5 7 2
## Scary movie!!!
## 1
Question 9
sum(genre == "Drama")
## [1] 7
Question 10
boxoffice.millions[m.names == "A Bug's Life"]
## [1] 363.0894
genre[m.names == "A Bug's Life"]
## [1] "Adventure"
rating[m.names == "A Bug's Life"]
## [1] "G"
Question 11
sum(m.names == "Pirate's of the Caribbean")
## [1] 0
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"
mean(boxoffice.millions[genre == "Comedy"])
## [1] 90.37994
Questiom 13
m.names[boxoffice.millions > 50]
## [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"
Question 14
min(boxoffice.millions[genre %in% c("Comedy", "Drama")])
## [1] 14.15675
m.names[min(boxoffice.millions[genre %in% c("Comedy", "Drama")])]
## [1] "Soul Plane"
Question 15
time.finite <- time[is.finite(time)]
time.finite
## [1] 121 100 112 129 96 111 123 121 93 106
median(time.finite)
## [1] 111.5
median(time.finite) / 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"