1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| num_matrix <- matrix(1:6, nrow = 2, ncol = 3)
str_matrix <- matrix(c("apple", "banana", "cherry", "orange"), nrow = 2, ncol = 2) "banana" %in% str_matrix dim(num_matrix) length(num_matrix) nrow(num_matrix) ncol(num_matrix)
num_matrix[1, 2] num_matrix[2,] num_matrix[,2] num_matrix[1, c(2,3)] num_matrix[,c(2,3)]
new_matrix <- rbind(num_matrix, c(7, 8, 9)) new_matrix <- cbind(new_matrix, c(10, 11))
new_matrix <- new_matrix[-1, ] new_matrix <- new_matrix[, -c(2,3)]
for (i in 1:nrow(new_matrix)) { for (j in 1:ncol(new_matrix)) { print(new_matrix[i, j]) } }
matrix1 <- matrix(c(1,2,3,4), nrow = 2, ncol = 2) matrix2 <- matrix(c(5,6,7,8), nrow = 2, ncol = 2) combined_matrix <- rbind(matrix1, matrix2) dim(combined_matrix) combined_matrix <- cbind(matrix1, matrix2) dim(combined_matrix)
num_matrix <- matrix(1:6, nrow = 2, ncol = 3) dim(t(num_matrix))
num_matrix + 1 num_matrix - 1
num_matrix %*% t(num_matrix)
solve(matrix(1:9, nrow = 3, ncol = 3))
|