Simplifying loop for Incidence Matrix
I can't think of anything faster than:

a &lt;- matrix(diag(-1, n2), nrow = n2, ncol = n1 * n2)


The n2 * n2 values inside diag(-1L, n2) will be recycled n1 times to fill the final matrix of dimensions n2-by-n1*n2.