I work primarily in MATLAB but I think the answer should not be too hard to carry over from one language to another.

## Why is this naive matrix multiplication faster than base R's?

In R, matrix multiplication is very optimized, i.e. is really just a call to BLAS/LAPACK. However, I'm surprised this very naive C++ code for matrix multiplication seems reliably 30% faster.

## Forming a 'partial' identity-matrix according to a partially filled vector

I'm currently forming a matrix from a vector in MATLAB following the scheme described below:Given is a vector x containing ones and zeros in an arbitrary order, e.g.