# Box office Star Wars (in millions!)new_hope <-c(460.998, 314.4)empire_strikes <-c(290.475, 247.900)return_jedi <-c(309.306, 165.8)# Construct matrixstar_wars_matrix <-matrix(c(new_hope, empire_strikes, return_jedi), nrow =3, byrow =TRUE)# Vectors region and titles, used for namingregion <-c("US", "non-US")titles <-c("A New Hope", "The Empire Strikes Back", "Return of the Jedi")# Name the columns with regioncolnames(star_wars_matrix)<-region# Name the rows with titlesrownames(star_wars_matrix)<-titles# Print out star_wars_matrixprint(star_wars_matrix)
US non-US
A New Hope 460.998 314.4
The Empire Strikes Back 290.475 247.9
Return of the Jedi 309.306 165.8
# Construct star_wars_matrixbox_office <-c(460.998, 314.4, 290.475, 247.900, 309.306, 165.8)region <-c("US", "non-US")titles <-c("A New Hope", "The Empire Strikes Back", "Return of the Jedi")star_wars_matrix <-matrix(box_office, nrow =3, byrow =TRUE,dimnames =list(titles, region))# Calculate worldwide box office figuresworldwide_vector <-rowSums(star_wars_matrix)print(worldwide_vector)
A New Hope The Empire Strikes Back Return of the Jedi
775.398 538.375 475.106
# Construct star_wars_matrixbox_office <-c(460.998, 314.4, 290.475, 247.900, 309.306, 165.8)region <-c("US", "non-US")titles <-c("A New Hope", "The Empire Strikes Back", "Return of the Jedi")star_wars_matrix <-matrix(box_office, nrow =3, byrow =TRUE,dimnames =list(titles, region))# The worldwide box office figuresworldwide_vector <-rowSums(star_wars_matrix)# Bind the new variable worldwide_vector as a column to star_wars_matrixall_wars_matrix <-cbind(star_wars_matrix,worldwide_vector)print(all_wars_matrix)
US non-US worldwide_vector
A New Hope 460.998 314.4 775.398
The Empire Strikes Back 290.475 247.9 538.375
Return of the Jedi 309.306 165.8 475.106
# # # star_wars_matrix and star_wars_matrix2 are available in your workspace# star_wars_matrix # star_wars_matrix2 # # # Combine both Star Wars trilogies in one matrix# all_wars_matrix <- rbind(star_wars_matrix,star_wars_matrix2)# print(all_wars_matrix)# ```# all_wars_matrix is available in your workspaceall_wars_matrix
US non-US worldwide_vector
A New Hope 460.998 314.4 775.398
The Empire Strikes Back 290.475 247.9 538.375
Return of the Jedi 309.306 165.8 475.106
# Total revenue for US and non-UStotal_revenue_vector <-colSums(all_wars_matrix)# Print out total_revenue_vectorprint(total_revenue_vector)
US non-US worldwide_vector
1060.779 728.100 1788.879
# all_wars_matrix is available in your workspaceall_wars_matrix
US non-US worldwide_vector
A New Hope 460.998 314.4 775.398
The Empire Strikes Back 290.475 247.9 538.375
Return of the Jedi 309.306 165.8 475.106
# Select the non-US revenue for all moviesnon_us_all <- all_wars_matrix[,2]# Average non-US revenuemean(non_us_all)
[1] 242.7
# Select the non-US revenue for first two moviesnon_us_some <- all_wars_matrix[1:2,2]# Average non-US revenue for first two moviesmean(non_us_some)
[1] 281.15
# all_wars_matrix is available in your workspaceall_wars_matrix
US non-US worldwide_vector
A New Hope 460.998 314.4 775.398
The Empire Strikes Back 290.475 247.9 538.375
Return of the Jedi 309.306 165.8 475.106
# Estimate the visitorsvisitors <- all_wars_matrix/5# Print the estimate to the consoleprint(visitors)
US non-US worldwide_vector
A New Hope 92.1996 62.88 155.0796
The Empire Strikes Back 58.0950 49.58 107.6750
Return of the Jedi 61.8612 33.16 95.0212
# all_wars_matrix and ticket_prices_matrix are available in your workspaceall_wars_matrix
US non-US worldwide_vector
A New Hope 460.998 314.4 775.398
The Empire Strikes Back 290.475 247.9 538.375
Return of the Jedi 309.306 165.8 475.106
print(all_wars_matrix)
US non-US worldwide_vector
A New Hope 460.998 314.4 775.398
The Empire Strikes Back 290.475 247.9 538.375
Return of the Jedi 309.306 165.8 475.106
str(all_wars_matrix)
num [1:3, 1:3] 461 290 309 314 248 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:3] "A New Hope" "The Empire Strikes Back" "Return of the Jedi"
..$ : chr [1:3] "US" "non-US" "worldwide_vector"
# Estimated number of visitorsvisitors <- all_wars_matrix/ticket_prices_matrix# US visitorsus_visitors <- visitors[,1]# Average number of US visitorsprint(mean(us_visitors))