title: Reducing number of factor levels before modelling
body: <p>I have a factor with 2600 levels and I want to reduce it to ~10 before modelling</p>
  
  <p>I thought I could do this with an operation that says "if a factor is listed fewer than x times, it should be placed into a bucket called "other"</p>
  
  <p>Here is some example data:</p>
  
  <pre><code>df &lt;- data.frame(colour=c("blue","blue","blue","green","green","orange","grey"))
  </code></pre>
  
  <p>And this is the output I am hoping for:</p>
  
  <pre><code>  colour
  1   blue
  2   blue
  3   blue
  4  green
  5  green
  6  other
  7  other
  </code></pre>
  
  <p>I have tried the below:</p>
  
  <pre><code>df %&gt;% mutate(colour = ifelse(count(colour) &lt; 2, 'other', colour))
  </code></pre>
  
  <blockquote>
    <p>Error in mutate_impl(.data, dots) : 
          Evaluation error: no applicable method for 'groups' applied to an object of class "factor".</p>
  </blockquote>