title: R regroup factor levels based on frequency
body: <p>In order to use <code>tree()</code> I can have no more than 32 levels for a factor. My factor <code>mydata$auction</code> has more than 32 levels. How can I regroup the levels that have low frequency, say, &lt;10?</p>
  
  <p>I tried:</p>
  
  <pre><code>mydata$auction[count(n$freq)&lt;10] &lt;- "OTHER" # didn't do it right
  levels(mydata$auction)[n&lt;=10] &lt;-"OTHER" # didn't do it right
  </code></pre>
  
  <p>Here's what the data looks like:</p>
  
  <pre><code>   price  sale_date ext_color mileage ZipCode RFL FLNDR auction region condition
  1  25000 2004-01-06     BEIGE    3571       1   L     L    AAAI      3        RG
  2  27500 2004-01-14     BEIGE    5654       6   R     N    KCAA      5      &lt;NA&gt;
  3  26100 2004-01-14     BEIGE    5453       9   L     L    BCAA      6      &lt;NA&gt;
  4  27000 2004-01-28     BEIGE    6400       8   L     D     DAA      5      &lt;NA&gt;
  5  23300 2004-03-04     BEIGE   12445       9   L     L    SCAA      6        RG
  6  28000 2004-03-11     BEIGE    3019       9   L     L    SCAA      6        AV
  7  27300 2004-03-16     BEIGE    4377       1   L     L    AAAI      3        RG
  8  25900 2004-03-16     BEIGE    6727       1   L     L    AAAI      3        RG
  9  28200 2004-03-18     BEIGE    9962       4   L     L    GDTA      4        AV
  10 26300 2004-03-18     BEIGE   13012       9   L     L    SCAA      6        AV
  11 26400 2004-03-25     BEIGE   20473       4   L     L    GDTA      4        AV
  12 26400 2004-03-25     BEIGE   20745       4   L     L    GDTA      4        AV
  13 28000 2004-03-25     BEIGE   10995       4   L     L    GDTA      4        AV
  14 28300 2004-03-31     BEIGE    8042       1   R     N     BAA      3      &lt;NA&gt;
  15 28500 2004-04-01     BEIGE    5938       8   F     F     DAA      5      &lt;NA&gt;
  16 26200 2004-04-07     BEIGE    6704       3   R     N    OCAA      1      &lt;NA&gt;
  17 27300 2004-04-08     BEIGE    5495       4   R     N    CINA      4      &lt;NA&gt;
  18 27700 2004-04-08     BEIGE    1301       9   R     N    SCAA      6      &lt;NA&gt;
  19 28700 2004-04-08     BEIGE    5659       6   R     N    GCAA      4      &lt;NA&gt;
  20 28000 2004-04-08     BEIGE   13032       6   L     L    SLAA      5        AV
  21 26000 2004-04-08     BEIGE   23990       4   F     F    SAAA      5        AV
  22 28300 2004-04-08     BEIGE   11025       4   F     F     BAA      3      &lt;NA&gt;
  23 27700 2004-04-13     BEIGE   13129       6   L     L    SLAA      5        AV
  24 27100 2004-04-13     BEIGE    8559       2   L     L    BWAE      3        CL
  25 27500 2004-04-13     BEIGE   11647       6   L     L    SLAA      5        AV
  26 26000 2004-04-13     BEIGE    2082       2   L     L    SVAA      2      &lt;NA&gt;
  27 27400 2004-04-13     BEIGE   11977       6   L     L    SLAA      5        AV
  28 26500 2004-04-13     BEIGE   18756       4   L     L    DETA      4        AV
  29 27000 2004-04-13     BEIGE   10048       4   F     F    NSAA      4      &lt;NA&gt;
  30 27200 2004-04-13     BEIGE   10490       4   F     F    NSAA      4      &lt;NA&gt;
  </code></pre>