I have a matrix with diagonals equal to zero and off-diagonals equal to unity (inverse to the identity matrix):
mat1 <- matrix(c(0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0), 5, 5)
I also have a vector that always has the same length as the dims of the matrix, and always starts from zero:
vec1 <- c(0,1,2,3,4)
using these two objects, I want to create a matrix that looks like this:
mat2 <- matrix(c(0,1,2,3,4,1,0,1,2,3,2,1,0,1,2,3,2,1,0,1,4,3,2,1,0), 5, 5)
[,1] [,2] [,3] [,4] [,5]
[1,] 0 1 2 3 4
[2,] 1 0 1 2 3
[3,] 2 1 0 1 2
[4,] 3 2 1 0 1
[5,] 4 3 2 1 0
I want an operation that will generalize so that if I have a dims matrix of 9 by 9, for example, and a 0: 8 vector, I can achieve an equivalent result. Any ideas on how to approach this?