Create a matrix and calculate the row-wise and column-wise sums.
EasyProblem Statement
Create a matrix and calculate the row-wise and column-wise sums.
Sample Input
Matrix: [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 5 6
Sample Output
Row-wise sums: 3 7 11 Column-wise sums: 9 12
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
# Predefined structure
matrix <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 3, byrow = TRUE)
row_sums <- rowSums(matrix)
col_sums <- colSums(matrix)
print(paste("Row-wise sums:", paste(row_sums, collapse = " ")))
print(paste("Column-wise sums:", paste(col_sums, collapse = " ")))
Input
Matrix: [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 5 6
Expected Output
Row-wise sums: 3 7 11 Column-wise sums: 9 12