title: R dataframe: select rows by sorting one column and based on values in two columns
body: <p>I have a dataframe <code>df</code> as below:</p>
  
  <pre><code>user_id     rating      date          status
  10506       4           2008-11-11    2
  10506       3           2008-11-13    1
  10506       4           2008-11-23    3
  10506       2           2008-11-29    4
  10506       1           2009-01-15    3
  10506       1           2009-11-11    2
  10507       3           2007-10-20    1
  10507       5           2007-11-11    1
  10507       2           2007-12-21    2
  10507       5           2008-01-08    3
  10507       4           2008-01-31    3
  10507       3           2008-02-05    4
  10507       4           2008-03-10    2
  </code></pre>
  
  <p>I would like to do the following two operations:</p>
  
  <ol>
  <li><p>Select three rows for each <code>user_id</code> with the earliest <code>date</code>. I know that all <code>user_id</code> have at least three observations. <code>date</code> is not in date format, but when I order by <code>date</code>, I am able to get in chronological order.</p></li>
  <li><p>Select three rows for each <code>user_id</code> with earliest <code>date</code> where <code>status</code> is 3 or 4.</p></li>
  </ol>
  
  <p>Is there any <code>dplyr</code> solution where I can group by <code>user_id</code> and then select first three rows after sorting <code>date</code> in ascending order? Any help is appreciated.</p>
  
  <p>Edits:</p>
  
  <p>I corrected a typo in dummy data I provided in the question. Apologies for making this error. Also, including an expected output to make things clear:</p>
  
  <p>Output for part 1:</p>
  
  <pre><code>user_id     rating      date          status
  10506       4           2008-11-11    2
  10506       3           2008-11-13    1
  10506       4           2008-11-23    3
  10507       3           2007-10-20    1
  10507       5           2007-11-11    1
  10507       2           2007-12-21    2
  </code></pre>
  
  <p>Output for part 2:</p>
  
  <pre><code>user_id     rating      date          status
  10506       4           2008-11-23    3
  10506       2           2008-11-29    4
  10506       1           2009-01-15    3
  10507       5           2008-01-08    3
  10507       4           2008-01-31    3
  10507       3           2008-02-05    4
  </code></pre>