title: Better way to write this R data-cleaning function?
body: <p>I am writing a R function that takes a dataframe column (probably preferably of type factor) and clumps together all the entries below a user-defined frequency as "other." This is done for data cleaning. </p>
  
  <p>Here is what I have written: </p>
  
  <pre><code>zcut &lt;- function(column, threshold){
    dft &lt;- data.frame(table(column))
    dft_ind &lt;- sapply(dft$Freq, function(x) x &lt; threshold)
    dft_list &lt;- dft[[1]][dft_ind]
    levels(column)[levels(column) %in% dft_list] &lt;- "Other"
    return(column)
  }
  </code></pre>
  
  <p>I think this is pretty straightforward, but are there ways to make my code more concise or exact? </p>
  
  <p>I would have asked this on the Code Review stack exchange, although it's not clear to me many R experts lurk there. </p>