title: Remove everything but the first rows from a subset R
body: <p>I have  a large dataset which I want remove all the rows except for the first 8 per value of 1 variable. (in this example only the first one)</p>
  <p>example set:</p>
  <pre><code>   Time &lt;- c(1:20)
      stimulus &lt;- c(rep(&quot;happy 1&quot;,4),rep(&quot;happy 2&quot;,4),rep(&quot;disgust 1&quot;,4),rep(&quot;anger 1&quot;,4),rep(&quot;sad 1&quot;,4))
      Happy &lt;- c(runif(20,0,1))
      Disgust &lt;- c(runif(20,0,1))
      Anger &lt;- c(runif(20,0,1))
      Subj1&lt;- data.frame(Time,stimulus,Happy,Disgust,Anger)
  </code></pre>
  <p>SO: I want to remove all rows except for Subj1$stimulus 1st row of &quot;happy 1&quot;, &quot;happy 2&quot;, &quot;disgust 1&quot; etc.
  I manage to do so by subsetting to a new variable and then de-selecting everything but the first 8 rows using the following code:</p>
  <pre><code>Stim1&lt;-which(Subj1$stimulus==&quot;happy 1&quot;)
  Subj1&lt;- Subj1[-c(Stim1[2:length(Stim1)]),]
  </code></pre>
  <p>However, I want to automatically run this for all stimulus variables. Another thing that makes this more difficult is that the row numbers jump because of the removal of rows.</p>