title: Subset data frame based on number of rows per group
body: <p>I have data like this, where some "name" occurs more than three times:</p>
  
  <pre><code>df &lt;- data.frame(name = c("a", "a", "a", "b", "b", "c", "c", "c", "c"), x = 1:9)
  
    name x
  1    a 1
  2    a 2
  3    a 3
  4    b 4
  5    b 5
  6    c 6
  7    c 7
  8    c 8
  9    c 9
  </code></pre>
  
  <p>I wish to subset (filter) the data based on number of rows (observations) within each level of the <code>name</code> variable. If a certain level of <code>name</code> occurs more than say 3 times, I want to remove all rows belonging to that level. So in this example, we would drop observations where <code>name == c</code>, since there are <code>&gt; 3</code> rows in that group:</p>
  
  <pre><code>  name x
  1    a 1
  2    a 2
  3    a 3
  4    b 4
  5    b 5
  </code></pre>
  
  <p>I wrote this code, but can't get it to work. </p>
  
  <pre><code>as.data.frame(table(unique(df)$name))
  subset(df, name &gt; 3)
  </code></pre>