Combining elements in a string vector with defined element size and accounting for not event sizes
<p>Given is vector:</p>

<pre><code>vec &lt;- c(LETTERS[1:10])
</code></pre>

<p>I would like to be able to combine it in a following manner:</p>

<pre><code>resA &lt;- c("AB", "CD", "EF", "GH", "IJ")
resB &lt;- c("ABCDEF","GHIJ")
</code></pre>

<p>where elements of the vector <code>vec</code> are merged together according to the desired size of a new element constituting the resulting vector. This is <strong>2</strong> in case of <code>resA</code> and <strong>5</strong> in case of <code>resB</code>.</p>

<h2>Desired solution characteristics</h2>

<ul>
<li>The solution should allow for flexibility with respect to the element sizes, i.e. I may want to have vectors with elements of size 2 or 20</li>
<li><em>There may be not enough elements in the vector to match the desired chunk size,</em> in that case last element should be shortened accordingly (as shown)</li>
<li>This is shouldn't make a difference but the solution should work on <em>words</em> as well</li>
</ul>

<hr>

<h1>Attempts</h1>

<p>Initially, I was thinking of using something on the lines:</p>

<pre><code>c(
  paste0(vec[1:2], collapse = ""),
  paste0(vec[3:4], collapse = ""),
  paste0(vec[5:6], collapse = "")
  # ...
)
</code></pre>

<p>but this would have to be adapted to jump through the remaining pairs/bigger groups of the <code>vec</code> and handle last group which often would be of a smaller size.</p>