title: How to remove N rows of a data frame, according to conditions
body: <p>My question follows on from <a href="https://stackoverflow.com/questions/35403375/how-to-find-tail-rows-of-a-data-frame-that-satisfy-set-criteria/35403553?noredirect=1#comment58521929_35403553">How to find tail rows of a data frame that satisfy set criteria?</a> and as such, my (updated) sample data is structured as:</p>
  
  <pre><code>Individ &lt;- data.frame(Participant = c("Bill", "Bill", "Bill", "Bill", "Bill", "Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Bill", "Bill", "Bill", "Bill"),  
                        Time = c(1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4),
                        Condition = c("Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Expr", "Expr", "Expr", "Expr", "Expr", "Expr", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Placebo", "Expr", "Expr", "Expr", "Expr"),
                        Location = c("Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Away", "Away", "Away", "Away"),
                        Power = c(400, 250, 180, 500, 300, 600, 512, 300, 500, 450, 200, 402, 210, 130, 520, 310, 451, 608, 582, 390, 570))
  </code></pre>
  
  <p>I have learnt to find the tail row for each <code>Participant</code> across the different <code>Condition</code> plus <code>Location</code> based on their last occurrence of <code>Power</code>. I now wish to delete the last 3 rows from each <code>Participant</code> for each <code>Condition</code> and <code>Location</code>. However, the <code>Time</code> collected for each <code>Participant</code> and <code>Condition</code> differs and therefore I can not delete rows purely based on a standardised <code>Time</code>. </p>
  
  <p>How can I quickly iterate through each <code>Participant</code> and their respective <code>Condition</code>plus <code>Location</code> and delete the final 3 rows? My actual data frame is 4 million rows + with over 50 participants so ideally, a solution that iterates over each <code>Participant</code> and <code>Condition</code> would be desirable. </p>
  
  <p>My anticipated output would be:</p>
  
  <pre><code>Output &lt;- data.frame(Participant = c("Bill", "Bill", "Jane", "Jane", "Jane", "Jane", "Jane", "Jane", "Bill"),
                       Time = c(1, 2, 1, 2, 3, 1, 2, 3, 1),
                       Condition = c("Placebo", "Placebo", "Expr", "Expr", "Expr", "Placebo", "Placebo", "Placebo", "Expr"),
                       Location = c("Home", "Home", "Home", "Home", "Home", "Home", "Home", "Home", "Away"),
                       Power = c(400, 250, 600, 512, 300, 402, 210, 130, 608))
  </code></pre>