The total box office revenue for the entire saga

Just like cbind() has rbind(), colSums() has rowSums(). Your R workspace already contains the all_wars_matrix that you constructed in the previous exercise; type all_wars_matrix to have another look. Let's now calculate the total box office revenue for the entire saga.

Instruction

# Construct matrix load(url("http://s3.amazonaws.com/assets.datacamp.com/course/intro_to_r/all_wars_matrix.RData")) # all_wars_matrix is available in your workspace all_wars_matrix # Total revenue for US and non-US total_revenue_vector <- # Print out total_revenue_vector # all_wars_matrix is available in your workspace all_wars_matrix # Total revenue for US and non-US total_revenue_vector <- colSums(all_wars_matrix) # Print out total_revenue_vector total_revenue_vector msg = "Do not change the contents of `all_wars_matrix`; it was created for you in the workspace." test_object("all_wars_matrix", eq_condition = "equal", undefined_msg = msg, incorrect_msg = msg) test_function("colSums", "x", incorrect_msg = "Did you use the `colSums()` function on the all_wars_matrix?") test_object("total_revenue_vector", incorrect_msg = "Have you correctly assigned the result of `colSums(all_wars_matrix)` to `total_revenue_vector`?") test_output_contains("total_revenue_vector", incorrect_msg = "Don't forget to print out `total_revenue_vector`!") success_msg("Bellissimo! Head over to the next exercise to learn matrix subsetting.")

You should use the colSums() function with star_wars_matrix as the argument to find the total box office per region.

Previous: 3-6 | Adding a row

Next: 3-8 | Selection of matrix elements

Back to Main