title: How to format variables to filter through elements on R
body: <pre><code>v &lt;- files[1:4]
  y &lt;- fname[1:4]
  date_range &lt;- substr(y[1], 7, 23)
  </code></pre>
  <p>How do I make it so that v and y have it so that files[1:4] then becomes file[5:8] and then files[9:13] and so on. I assume it's a for loop, but I'm not sure how to format it. In addition, how do I make it so that date_range uses the first element that v and y use (aka for the first it would be 1 and then 5 and then 9, and so on).</p>
  <h2>Data</h2>
  <pre class="lang-r prettyprint-override"><code># files[1:10]
  files &lt;- c(&quot;1858/FailedToProcess/TOR-D-18580907-18580908.tif&quot;, 
  &quot;1858/FailedToProcess/TOR-D-18580907-18580908.tif-FailToProcess-Data.RDS&quot;,
  &quot;1858/FailedToProcess/TOR-D-18580907-18580908.tif-FailToProcess-Plot.png&quot;,
  &quot;1858/FailedToProcess/TOR-D-18580907-18580908.tif.png&quot;,
  &quot;1858/FailedToProcess/TOR-D-18580908-18580909.tif&quot;,                  
  &quot;1858/FailedToProcess/TOR-D-18580908-18580909.tif-FailToProcess-Data.RDS&quot;,
  &quot;1858/FailedToProcess/TOR-D-18580908-18580909.tif-FailToProcess-Plot.png&quot;,
  &quot;1858/FailedToProcess/TOR-D-18580908-18580909.tif.png&quot;,
  &quot;1858/FailedToProcess/TOR-D-18580910-18580911.tif&quot;,                       
  &quot;1858/FailedToProcess/TOR-D-18580910-18580911.tif-FailToProcess-Data.RDS&quot;)
  
  # fname[1:10]
  fname &lt;- c(&quot;TOR-D-18580907-18580908.tif&quot;,                       
  &quot;TOR-D-18580907-18580908.tif-FailToProcess-Data.RDS&quot;,
  &quot;TOR-D-18580907-18580908.tif-FailToProcess-Plot.png&quot;,
  &quot;TOR-D-18580907-18580908.tif.png&quot;,                   
  &quot;TOR-D-18580908-18580909.tif&quot;,                       
  &quot;TOR-D-18580908-18580909.tif-FailToProcess-Data.RDS&quot;,
  &quot;TOR-D-18580908-18580909.tif-FailToProcess-Plot.png&quot;,
  &quot;TOR-D-18580908-18580909.tif.png&quot;,                   
  &quot;TOR-D-18580910-18580911.tif&quot;,                       
  &quot;TOR-D-18580910-18580911.tif-FailToProcess-Data.RDS&quot;)
  </code></pre>
  <p>Both of these variables include over 100000 elements so I included just the first 10 of each, but they're both essentially just a VERY long list.</p>
  <hr />
  <p>EDIT:</p>
  <pre><code>i &lt;- 1 
  while (i &lt;= length(files)) {
    start &lt;- i 
    end &lt;- start + 3
    
    v &lt;- files[start:end]
    y &lt;- fname[start:end]
    date_range &lt;- substr(y[1], 7, 23)
    html_block &lt;- make_div(v, date_range)
    
    i &lt;- i + 4
  }
  </code></pre>