Please note, solutions are available here.
Create three vectors
x,y,z with integers and each vector has 3 elements. Combine the three vectors to become a 3×3 matrix
A where each column represents a vector. Change the row names to
Think: How about each row represents a vector, can you modify your code to implement it?
Please check your result from Exercise 1, using
is.matrix(A). It should return
TRUE, if your answer is correct. Otherwise, please correct your answer. Hint: Note that
is.matrix() will return
FALSE on a non-matrix type of input. Eg: a vector and so on.
Create a vector with 12 integers. Convert the vector to a 4*3 matrix
matrix(). Please change the column names to
x, y, z and row names to
a, b, c, d.
matrix() is set to be
FALSE by default. Please change it to
TRUE and print
B to see the differences.
Please obtain the transpose matrix of
tB is a 3×4 matrix. By the rule of matrix multiplication in algebra, can we perform
tB*tB in R language? (Is a 3×4 matrix multiplied by a 3×4 allowed?) What result would we get?
As we can see from Exercise 5, we were expecting that
tB*tB would not be allowed because it disobeys the algebra rules. But it actually went through the computation in R. However, as we check the output result , we notice the multiplication with a single
* operator is performing the componentwise multiplication. It is not the conventional matrix multiplication. How to perform the conventional matrix multiplication in R? Can you compute matrix
If we convert
A to a
data.frame type instead of a
matrix , can we still compute a conventional matrix multiplication for matrix
A multiplies matrix
A ? Is there any way we could still perform the matrix multiplication for two
data.frame type variables? (Assuming proper dimension)
Extract a sub-matrix from
subB . It should be a 3×3 matrix which includes the last three rows of matrix
B and their corresponding columns.
A-subB . Can we compute
Generate a n * n matrix (square matrix)
A1 with proper number of random numbers, then generate another n * m matrix
If we have
A1*M=A2 (Here * represents the conventional multiplication), please solve for
Hint: use the
solve() functions. E.g.,
runif(9) should give you 9 random numbers.