title: Split dataframe into minimum n observation and do it for all rows in R
body: <p>I have a question about dividing the dataset into several rows by function that we can set the number of minimal observations should contain in it.</p>
  <p>Let say I have a data frame df with 8 observation:</p>
  <pre><code>df &lt;- tibble(x = sort(sample(10:90, 8)), y = c(&quot;N&quot;,&quot;M&quot;, &quot;N&quot;, &quot;M&quot;, &quot;N&quot;, &quot;N&quot;, &quot;M&quot;, &quot;M&quot;))
  
  # A tibble: 8 x 2
        x y    
    &lt;int&gt; &lt;chr&gt;
  1    13 N    
  2    14 M    
  3    15 N    
  4    43 M    
  5    49 N    
  6    55 N    
  7    56 M    
  8    74 M   
  </code></pre>
  <p>I want to split it with n values, let say I want the <code>n=3</code>, the output must be a data frame with the minimal number of 3 rows and the other should 5. Next, it iterates, and appends by one row and stops until it finds the number of observations of both less than 3. I want to save this data frame in a separate df. Let say df_3 and dfo_5, df_4 and dfo_4</p>
  <p>It maybe sounds confusing I will put the example of output that I suggested, let say I want the <code>n=3</code></p>
  <pre><code># rows df_3
        x y    
    &lt;int&gt; &lt;chr&gt;
  1    13 N    
  2    14 M    
  3    15 N  
  
  # dfo_5 = the remain df have 5 rows
        x y    
    &lt;int&gt; &lt;chr&gt;
  1    43 M    
  2    49 N    
  3    55 N    
  4    56 M    
  5    74 M  
  </code></pre>
  <pre><code># rows df_4
        x y    
    &lt;int&gt; &lt;chr&gt;
  1    13 N    
  2    14 M    
  3    15 N    
  4    43 M  
  
  # dfo_4 = the remain df have 4 rows
        x y    
    &lt;int&gt; &lt;chr&gt;
  1    49 N    
  2    55 N    
  3    56 M    
  4    74 M   
  </code></pre>
  <pre><code># 
  # 
  # rows df_6 is 6 ( i will not save this)
        x y    
    &lt;int&gt; &lt;chr&gt;
  1    13 N    
  2    14 M    
  3    15 N    
  4    43 M    
  5    49 N    
  6    55 N   
  
  # because the remainder df contains less 3 rows
        x y    
    &lt;int&gt; &lt;chr&gt;
  1    56 M    
  2    74 M    
  
  
  </code></pre>
  <p>From these df's I want to apply the proportion of M and N respectively</p>
  <pre><code>function (df,n){
  for df split into n
  to be df1 and df2
  if nrow in df1 and df2 &lt; 3
  then stop
  
  }
  
  apply proportion M for df1
  apply proportion M for df2
  </code></pre>
  <p>A help will be much appreciated. Thank You</p>