title: Match datasets R
body: <p>I have two datasets of which one is a subset of the other, which is the one with the values I am interested in (Dataset2). But the problem is, that in that dataset I can't tell which enteries belong together. In dataset1 those &quot;groups&quot; are defined as the enteries between the &quot;Top&quot; enteries.</p>
  <pre><code>Dataset1:       Dataset2:
  1 &quot;Top&quot;         &quot;Name1&quot;
  2 &quot;Name1&quot;       &quot;Name2&quot;
  3 &quot;Name2&quot;       &quot;Name5&quot;
  4 &quot;Name3&quot;       &quot;Name6&quot;
  5 &quot;Top&quot;
  6 &quot;Name4&quot;
  7 &quot;Name5&quot;
  8 &quot;Top&quot;
  9 &quot;Name6&quot;
  10 &quot;Top&quot;
  </code></pre>
  <p>As a result I need somethin like how many enteries are in which group to replicate the group names that often to give a result like that:</p>
  <pre><code>Result:
     Group     Name
  1 &quot;Group1&quot;   &quot;Name1&quot;
  2 &quot;Group1&quot;   &quot;Name2&quot;
  3 &quot;Group2&quot;   &quot;Name5&quot;
  4 &quot;Group3&quot;   &quot;Name6&quot;
  </code></pre>
  <p><strong>EDIT:</strong>
  <strong>I made a mistake in my dummy data, the names are not unique for each group. It looks something like this:</strong></p>
  <pre><code>Dataset1:       Dataset2:
  1 &quot;Top&quot;         &quot;Name1&quot;
  2 &quot;Name1&quot;       &quot;Name2&quot;
  3 &quot;Name2&quot;       &quot;Name3&quot;
  4 &quot;Name3&quot;       &quot;Name3&quot;
  5 &quot;Top&quot;         &quot;Name5&quot;
  6 &quot;Name3&quot;
  7 &quot;Name4&quot;
  8 &quot;Top&quot;
  9 &quot;Name5&quot;
  10 &quot;Top&quot;
  </code></pre>
  <pre><code>Result:
     Group     Name
  1 &quot;Group1&quot;   &quot;Name1&quot;
  2 &quot;Group1&quot;   &quot;Name2&quot;
  3 &quot;Group1&quot;   &quot;Name3&quot;
  4 &quot;Group2&quot;   &quot;Name3&quot;
  5 &quot;Group3&quot;   &quot;Name5&quot;
  </code></pre>