title: Can we build a R function/Logic to get record IDs by grouping columns
body: <p>I have below dataset where I want to create a &quot;New_Record_ID&quot; column using the &quot;Current_Record_ID&quot; and &quot;Stores&quot;.</p>
  <p>For every repeating Current_Record_ID there should only be 2 stores. If Stores exceeds by 2 the record ID should change and increase by +1 to the previous record ID( Expected result).</p>
  <p>Sample dataframe:</p>
  <pre><code>df &lt;- data.frame(Stores=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12,13,14,15,16,17,18,19,20),
                   Current_Record_ID=c(1, 1, 2, 3, 3, 3, 4, 4, 4, 4,4,4,4,5,5,6,7,7,7,8))
  </code></pre>
  <p>Expected Result:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">Stores</th>
  <th style="text-align: center;">Current_Record_ID</th>
  <th style="text-align: center;">New_Record_ID</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">1</td>
  </tr>
  <tr>
  <td style="text-align: center;">2</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">1</td>
  </tr>
  <tr>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">2</td>
  <td style="text-align: center;">2</td>
  </tr>
  <tr>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">3</td>
  </tr>
  <tr>
  <td style="text-align: center;">5</td>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">3</td>
  </tr>
  <tr>
  <td style="text-align: center;">6</td>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">4</td>
  </tr>
  <tr>
  <td style="text-align: center;">7</td>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;">5</td>
  </tr>
  <tr>
  <td style="text-align: center;">8</td>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;">5</td>
  </tr>
  <tr>
  <td style="text-align: center;">9</td>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;">6</td>
  </tr>
  <tr>
  <td style="text-align: center;">10</td>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;">6</td>
  </tr>
  <tr>
  <td style="text-align: center;">11</td>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;">7</td>
  </tr>
  <tr>
  <td style="text-align: center;">12</td>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;">7</td>
  </tr>
  <tr>
  <td style="text-align: center;">13</td>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;">8</td>
  </tr>
  <tr>
  <td style="text-align: center;">14</td>
  <td style="text-align: center;">5</td>
  <td style="text-align: center;">9</td>
  </tr>
  <tr>
  <td style="text-align: center;">15</td>
  <td style="text-align: center;">5</td>
  <td style="text-align: center;">9</td>
  </tr>
  <tr>
  <td style="text-align: center;">16</td>
  <td style="text-align: center;">6</td>
  <td style="text-align: center;">10</td>
  </tr>
  <tr>
  <td style="text-align: center;">17</td>
  <td style="text-align: center;">7</td>
  <td style="text-align: center;">11</td>
  </tr>
  <tr>
  <td style="text-align: center;">18</td>
  <td style="text-align: center;">7</td>
  <td style="text-align: center;">11</td>
  </tr>
  <tr>
  <td style="text-align: center;">19</td>
  <td style="text-align: center;">7</td>
  <td style="text-align: center;">12</td>
  </tr>
  <tr>
  <td style="text-align: center;">20</td>
  <td style="text-align: center;">8</td>
  <td style="text-align: center;">13</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>*Also if we have a larger data set of n stores and Currect_Record_ID and we want to fix stores/not to exceed 100 counts. How can we will create the New_record_ID .?</p>