title: Replace value in a column based on a Frequency Count using R
body: <p>I have a dataset with multiple columns. Many of these columns contain over 32 factors, so to run a Random Forest (for example), I want to replace values in the column based on their Frequency Count.</p>
  
  <p>One of the column reads like this:</p>
  
  <pre><code>$ country                                    
  : Factor w/ 92 levels "China","India","USA",..: 30 39 39 20 89 30 16 21 30 30 ...
  </code></pre>
  
  <p>What I would like to do is only retain the top N (where N is a value between 5 and 20) countries, and replace the remaining values with "Other".
  I know how to calculate the frequency of the values using the table function, but I can't seem to find a solution for replacing values on the basis of such a rule. How can this be done?</p>