title: how to subset dataframe based on vector and then group by in dplyr
body: <p>I have following dataframe in R</p>
  
  <pre><code> ID        Blocks
   123       2D
   345       2E
   324       2D
   567       4F
   678       5E
   444       2D
   145       2D
  </code></pre>
  
  <p>Now I want to subset dataframe based on a vector and then on each subset I want to apply group by</p>
  
  <p>e.g    <code>vec &lt;- c(2,3,2)</code> Now First it should subset the dataframe with first two rows</p>
  
  <pre><code> df &lt;- df[1:2,]
   df %&gt;%
   group_by(Blocks) %&gt;%
   summarise(count = n())
  </code></pre>
  
  <p>Then it should subset the dataframe with next 3 rows</p>
  
  <pre><code> df &lt;- df[3:5,]
   df %&gt;%
   group_by(Blocks) %&gt;%
   summarise(count = n())
  </code></pre>
  
  <p>and so on. Desired output will be,</p>
  
  <pre><code> Subset    2D    2E     4F     5E
    2         1     1     0      0
    3         1     0     1      1
    2         2     0     0      0
  </code></pre>
  
  <p>Individually I can do with above code,but my dataframe is huge and I have to subset it many times.
  How can we do it more effectively in R?            </p>