I assume I work on a simple problem regarding subsetting data based on another column value (here patient), but cannot find the solution. I need a data subset for each patient who has been in the hospital at least 4 times. In other words, only patients who have been in the hospital for at least 4 times shall be shown with their 4 visit rows in the new df. My table looks like this:
</style>
<table class="tg">
<tr>
<th class="tg-yw4l">Patient</th>
<th class="tg-yw4l"># Hospital Visits</th>
<th class="tg-yw4l">Duration</th>
</tr>
<tr>
<td class="tg-yw4l">Monica</td>
<td class="tg-yw4l">1</td>
<td class="tg-yw4l">10D</td>
</tr>
<tr>
<td class="tg-yw4l">Jack</td>
<td class="tg-yw4l">1</td>
<td class="tg-yw4l">5D</td>
</tr>
<tr>
<td class="tg-yw4l">Monica</td>
<td class="tg-yw4l">2</td>
<td class="tg-yw4l">3D</td>
</tr>
<tr>
<td class="tg-yw4l">Eric</td>
<td class="tg-yw4l">1</td>
<td class="tg-yw4l">2D</td>
</tr>
<tr>
<td class="tg-yw4l">Eric</td>
<td class="tg-yw4l">2</td>
<td class="tg-yw4l">3D</td>
</tr>
<tr>
<td class="tg-yw4l">Monica</td>
<td class="tg-yw4l">3</td>
<td class="tg-yw4l">4D</td>
</tr>
<tr>
<td class="tg-yw4l">Jack</td>
<td class="tg-yw4l">2</td>
<td class="tg-yw4l">4D</td>
</tr>
<tr>
<td class="tg-yw4l">Eric</td>
<td class="tg-yw4l">3</td>
<td class="tg-yw4l">8D</td>
</tr>
<tr>
<td class="tg-yw4l">Eric</td>
<td class="tg-yw4l">4</td>
<td class="tg-yw4l">9D</td>
</tr>
</table>
Thank you very much!