title: Removing Specific factor level from factor variable
body: <p>I have a data frame that has several variables that have 5 factor levels. I want to delete only one of those levels. First I assigned all instances of of that level to NA, and then used the <code>droplevels</code> command to get rid the empty levels. </p>
  
  <p>However for one variable in my data frame one of the levels I don't want dropped has no observations in it. Is there a way to remove only a specific factor level, and not just the empty ones. </p>
  
  <p>Here is a reproducible example</p>
  
  <pre><code>df &lt;- data.frame(var1=rep(letters[1:5],2),var2=rep(letters[5:1],2),var3=c("a","c","d","e","a","c","d","e","a","c"))
  levels(df$var3)&lt;-c("a","c","d","e","b")
  </code></pre>
  
  <p>This sets up a data frame like mine. Now I want to remove all instances of the level e, and then drop it as a possible level. I do this with the code below.</p>
  
  <pre><code>df2&lt;-replace(df, df=="e",NA)
  df2&lt;-droplevels(df2)
  </code></pre>
  
  <p>The problem is when I use <code>droplevels</code> it drops level b from var3 also. I don't want to remove level b just level e from all of the variables. I have looked for a way to remove just a specific level, but have not found the answer. Can anyone show me how to remove just a specific factor level? What I would ideally like is a <code>droplevels</code> command that I can tell to just remove level e. Does such a function exist?</p>