Analyze matrices, you shall
It is now time to get your hands dirty. In the following exercises you will analyze the box office numbers of the Star Wars franchise. May the force be with you!
In the editor, three vectors are defined. Each one represents the box office numbers from the first three Star Wars movies. The first element of each vector indicates the US box office revenue, the second element refers to the Non-US box office (source: Wikipedia).
In this exercise, you'll combine all these figures into a single vector. Next, you'll build a matrix from this vector.
This exercise is part of the course
Introduction to R
Exercise instructions
- Use
c(new_hope, empire_strikes, return_jedi)
to combine the three vectors into one vector. Call this vectorbox_office
. - Construct a matrix with 3 rows, where each row represents a movie. Use the
matrix()
function to do this. The first argument is the vectorbox_office
, containing all box office figures. Next, you'll have to specifynrow = 3
andbyrow = TRUE
. Name the resulting matrixstar_wars_matrix
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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)
# Create box_office
box_office <-
# Construct star_wars_matrix
star_wars_matrix <-