Create following two matrices A and B with following elements.
A=,B=
Write R commands to do the following tasks:
(i) Multiply the two matrices.
(ii) Combine the two matrices row-wise.
(iii) Create a function that computes the following expression:
A 2+3*B
| X | Y | Z | W |
| 0.04 | 0.16 | 0.53 | A |
| 0.82 | 0.87 | 0.84 | A |
| 0.32 | 0.65 | 0.99 | A |
| 0.39 | 0.83 | 0.42 | A |
| 0.31 | 0.93 | 0.78 | A |
| 0.83 | 0.31 | 0.41 | A |
| 0.73 | 0.74 | 0.88 | A |
| 0.32 | 0.39 | 0.50 | B |
| 0.60 | 0.85 | 0.68 | B |
| 0.65 | 0.28 | 0.86 | B |
| 0.55 | 0.95 | 0.77 | B |
| 0.53 | 0.35 | 0.32 | B |
| 0.91 | 0.01 | 0.91 | B |
| 0.84 | 0.61 | 0.37 | B |
Write R commands to:
(i) Compute the group wise means of x, y and z according to the groups
defined by w column using apply family function.
(ii) Sort RData according the y column of it.
To perform the tasks outlined in the question using R, you can follow these steps:
1. Create Matrices A and B:
# Create matrices A and B
A <- matrix(c(1, 2, 0, 1), nrow = 2, ncol = 2, byrow = TRUE)
B <- matrix(c(-3, 1, 2, -1), nrow = 2, ncol = 2, byrow = TRUE)
2. Multiply the two matrices (i):
# Multiply matrices A and B
result <- A %*% B
3. Combine the two matrices row-wise (ii):
# Combine matrices A and B row-wise
combined <- rbind(A, B)
4. Create a function that computes the expression A^2 + 3*B (iii):
# Define a function
compute_expression <- function(A, B) {
result <- A^2 + 3 * B
return(result)
}
# Call
______ ___ __________ _______ ____ __________.
_________ _______ _____ ___ _________ ________ _______ _______ _______ _________.
______ ____ _________ ________ ___ ______ ________ _____ _________ ____ _________ _______.
______ _____ _________ ________ _________ ______ __________ _________.
________ _________ ____ __________ _____ ________ ___ ________.
______ _____ ______ __________ _________ _________ ____ ___.
______ _____ ______ ______ ___ _______ ______ ______.
_________ _____ _____ _________ _________ ___ ________ _______ ___ _________ _______.
_____ _____ ___ ____ ______ _________ _________.
_______ ______ _______ _______ ________ ________ ______ ________.
_______ _____ _________ ___ _____ __________.
_____ __________ _________ ___ _________ _______ _______ __________ _________.
_________ _____ __________ _________ ____ _________ ______ __________.
____ _________ ________ ________ _______.
__________ _____ _________ _____ ___ ___ ______ ________ _____ ________ ___.
_________ ________ ________ _____ ________ _________.
___ ____ ____ ________ ____ _______ ____ _______ ___.
__________ ________ ______ _______ _______ ______ _______ _________.
________ __________ __________ _________ _________.
_______ ________ _________ ___ ________ ______ _____ ______ _________ _______.
__________ ___ __________ ____ _________ ____ ________.
___ ______ ________ _________ ______.
_____ ______ __________ ______ __________ _______ _____ ________ ________.
____ __________ _____ __________ ______ ________ _________.
______ _________ ________ _________ __________ ____ ____ _______ ____ _________.
____ __________ ______ __________ _______ ____ _________ ________ __________ ____ __________.
______ ______ ______ ________ __________ _____ ____ ________ __________ ________ _________.
______ ____ ___.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required