title: Selecting top N rows for each group based on value in column
body: <p>I have dataframe like below :-</p>
  
  <pre><code>x&lt;-c(3,2,1,8,7,11,10,9,7,5,4)
  y&lt;-c("a","a","a", "b","b","c","c","c","c","c","c")
  z&lt;-c(2,2,2,1,1,3,3,3,3,3,3)
  df&lt;-data.frame(x,y,z)
  
  df
      x y z
  1   3 a 2
  2   2 a 2
  3   1 a 2
  4   8 b 1
  5   7 b 1
  6  11 c 3
  7  10 c 3
  8   9 c 3
  9   7 c 3
  10  5 c 3
  11  4 c 3
  </code></pre>
  
  <p>I want to select top n row for each group by column y where n is provided in column z. 
  So the output should be like :</p>
  
  <pre><code>output:
         x   y  z
       1 3   a  2
       2 2   a  2
       3 8   b  1
       4 11  c  3
       5 10  c  3
       6 9   c  3
  </code></pre>