In R, I have a matrix of...
data1 <- c(9,8,7,6,5,4,3,2,1,10,11,12,13,14,15)
matrix_1 <- matrix(data1,nrow=5,ncol=3,byrow=T)
Now that should create the matrix
[,1] [,2] [,3]
[1,] 9 8 7
[2,] 6 5 4
[3,] 3 2 1
[4,] 10 11 12
[5,] 13 14 15
My goal is to create a 6x4 matrix with that exact matrix for the first 5 rows and 3 columns, then the remaining row and column are sums of the respective row or column, then the single extra spot in the bottom right corner is the total sum of the entire first matrix (matrix_1).
I assume I need to use for loops, but I can't figure out how to get it. Thanks.
I tried messing with the for loop a bit, but I'm stuck on what to sum for that second matrix as well as how to cut the loop at the right point.