title: Rename factor levels based on a condition in R
body: <p>I want to combine all factors with a count less than n into one factor named "Else"</p>
  
  <p>For example if n = 3 then in the following df I want to combine "c", "d" and "e" as "Else":</p>
  
  <pre><code>df = data.frame(x=c(1:10), y=c("a","a","a","b","b","b","c","d","d","e"))
  </code></pre>
  
  <p>I started out by getting a df with all the low count values:</p>
  
  <pre><code>library(plyr)
  lowcounts = ddply(df, "y", function(z){if(nrow(z)&lt;3) nrow(z) else NULL})
  </code></pre>
  
  <p>I know I could change these manually but in practice I have dozens of levels so I need to automate this. </p>
  
  <p>I want to select and rename only the levels %in% lowcount in levels(df) and leave the rest the same but not sure how to proceed.  </p>