Created
May 23, 2019 00:52
-
-
Save renato04/785318942c9a49d5e60d9a410edc95e5 to your computer and use it in GitHub Desktop.
R Matrix operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Vector operations | |
a = c(333135, 19890804, 894, 478618, 2112) | |
b = a * 2 | |
c = b / 3 | |
d = c + a^2 | |
e = sqrt(d) | |
# Reverse matrix | |
ai = rev(a) | |
# Matrix operations | |
m1 = matrix(data = a, nrow = 5, ncol = 6, byrow = F) | |
m2 = matrix(data = a, nrow = 6, ncol = 5, byrow = F) | |
m3 = m1 * 0.1 | |
# matrix from data.frames | |
m4 = as.matrix(attitude[1:5, 1:6]) | |
# Matrix multiplication | |
m5 = m1 * m3 | |
m7 = m1 %*% m4 | |
# Matrix trans | |
m1t = t(m1) | |
# Diagonal Matrix | |
diag(c(1,2,3,4)) | |
# Solve Matrix | |
?solve | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment