--3-Matrices
#1-What's a matrix?
#Construct a matrix with 3 rows containing the numbers 1 up to 9,
# filled row-wise.
matrix(1:9,byrow=TRUE,nrow=3)#2-Analyzing matrices
#Use c(new_hope, empire_strikes, return_jedi) to combine-
#the three vectors into one vector. Call this vector box_office.
#Construct a matrix with 3 rows, where each row represents a movie.
#Use the matrix() function to this.
#The first argument is the vector box_office, containing
#all box office figures.
#Next, you'll have to specify nrow = 3 and byrow = TRUE.
#Name the resulting matrix star_wars_matrix.
# 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 <-c(new_hope,empire_strikes,return_jedi)
# Construct star_wars_matrix
star_wars_matrix <- matrix(box_office,byrow=TRUE,nrow=3)
star_wars_matrix#3-Naming a matrix
#4-Calculating the worldwide box office
#5-Adding a column for the Worldwide box office
#6-Adding a row
#7-The total box office revenue for the entire saga
#8-Selection of matrix elements
#9-A little arithmetic with matrices
#10- A little arithmetic with matrices (2)
Last updated