I am trying to find the count of diagonal 1s in each 3x3 tile e.g.
0 0 1 1 0 0
0 1 0 0 1 0
1 0 0 or 0 0 1
from the below 15x15 matrix.
set.seed(99)
mat <- matrix(sample(c(0,1), 225, prob=c(0.8,0.2), replace=TRUE), nrow=15)
print(mat)
[,1][,2][,3][,4][,5][,6][,7][,8][,9][,10][,11][,12][,13][,14][,15]
[1,] 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
[2,] 0 1 0 1 0 0 1 0 0 0 1 0 0 0 1
[3,] 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0
[4,] 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1
[5,] 0 0 0 0 1 0 0 1 1 1 0 0 0 0 0
[6,] 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0
[7,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[8,] 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0
[9,] 0 0 0 0 0 1 0 0 1 1 0 0 1 0 1
[10,] 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0
[11,] 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0
[12,] 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0
[13,] 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0
[14,] 1 1 0 1 1 0 0 0 0 1 0 0 0 0 1
[15,] 1 0 1 0 1 1 0 0 0 1 0 1 0 0 0
I expect the output to be 2 for the above matrix. Is there a way to do this with a for loop and if statements?