Split a matrix in blocks of size n with offset i (vectorized method)
<p>I want to split matrices of size <code>k x l</code> into blocks of size <code>n x n</code> considering an ofset <code>o</code> (Like Mathematica's <a href="http://reference.wolfram.com/language/ref/Partition.html#29979">Partition</a> function does).</p>

<p>For example, given a matrix <code>A</code> like </p>

<pre><code>A &lt;- matrix(seq(1:16), nrow = 4, ncol = 4)

     [,1] [,2] [,3] [,4]
[1,]    1    5    9   13
[2,]    2    6   10   14
[3,]    3    7   11   15
[4,]    4    8   12   16
</code></pre>

<p>and block size = 3, offset = 1, I want as output the four submatrices that I'd get from </p>

<pre><code>A[1:3, 1:3]
A[1:3, 2:4]
A[2:4, 1:3]
A[2:4, 2:4]
</code></pre>

<p>If offset were equal to 2 or 3, the output for this example should be only the submatrix that I get from</p>

<pre><code>A[1:3, 1:3]
</code></pre>

<p>How can I vectorize this?</p>