mat <- diag(3)
> mat
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 1 0
[3,] 0 0 1
I have a matrix with 1 along the diagonal and 0 everywhere else. I want to replace the 0s with 0.3, so the matrix looks like
> mat
[,1] [,2] [,3]
[1,] 1 0.3 0.3
[2,] 0.3 1 0.3
[3,] 0.3 0.3 1
What's a quick way of doing this?
