A little arithmetic with matrices (2)
Just like 2 * my_matrix
multiplied every element of my_matrix
by two, my_matrix1 * my_matrix2
creates a matrix where each element is the product of the corresponding elements in my_matrix1
and my_matrix2
.
After looking at the result of the previous exercise, big boss Lucas points out that the ticket prices went up over time. He asks to redo the analysis based on the prices you can find in ticket_prices_matrix
(source: imagination).
Those who are familiar with matrices should note that this is not the standard matrix multiplication for which you should use %*%
in R.
This exercise is part of the course
Introduction to R
Exercise instructions
- Divide
all_wars_matrix
byticket_prices_matrix
to get the estimated number of US and non-US visitors for the six movies. Assign the result tovisitors
. - From the
visitors
matrix, select the entire first column, representing the number of visitors in the US. Store this selection asus_visitors
. - Calculate the average number of US visitors; print out the result.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# all_wars_matrix and ticket_prices_matrix are available in your workspace
all_wars_matrix
ticket_prices_matrix
# Estimated number of visitors
visitors <-
# US visitors
us_visitors <-
# Average number of US visitors