title: Find Similar Word Pattern for Factor Variable using R
body: <p>I have <code>Data</code> with <code>10 000 Observations</code>, variable named <code>Com</code>, type <code>Factor</code> with <code>3000 Levels</code>. What I'm trying to do here is to find similar pattern between values in variable <code>Com</code> and then combine it into one. So, I can do analysis on it later. The <code>str</code> of <code>Data</code> is as below:</p>
  
  <pre><code>&gt; Data
   'data.frame':   10000 obs. of  1 variable:
    $ Com: Factor w/ 3000 levels
  </code></pre>
  
  <p>Example: <code>Frequency</code> of <code>Com</code>:</p>
  
  <pre><code>&gt; Frequency&lt;-data.frame(Com=c("C/C++ PROGRAMMING", "C; C++ PROGRAMMING", "C++ PROGRAMMING", "C++", "PROGRAMMING C++", "C", "C PROGRAMMING", "C, C++ PROGRAMMING", "PROGRAMMING IN C; C++", "PROGRAMMINGS IN C/C++","PROGRAMMING IN C/C++", "PROGRAMMING (C, C++, CUDA)"), Freq=c(2,3,3,1,2,5,6,2,1,3,4,5))
  &gt; Frequency
                                   Com   Freq
  1                  C/C++ PROGRAMMING      2
  2                 C; C++ PROGRAMMING      3
  3                    C++ PROGRAMMING      3
  4                                C++      1
  5                    PROGRAMMING C++      2
  6                                  C      5
  7                      C PROGRAMMING      6
  8                 C, C++ PROGRAMMING      2
  9              PROGRAMMING IN C; C++      1
  10             PROGRAMMINGS IN C/C++      3
  11              PROGRAMMING IN C/C++      4
  12        PROGRAMMING (C, C++, CUDA)      5       # Just add one more situation
  </code></pre>
  
  <p>I want the result of <code>Frequency</code> to be:</p>
  
  <pre><code>&gt; Frequency
                                   Com   Freq
  1                  C/C++ PROGRAMMING     15
  2                    C++ PROGRAMMING      6
  3                      C PROGRAMMING     11
  4         PROGRAMMING (C, C++, CUDA)      5
  </code></pre>
  
  <p>I can recode the levels of <code>Com</code> in order to this. However, there are <code>3000 Levels</code> for this variable <code>(Com)</code> and I have to find it one by one which going to take my time.</p>
  
  <p>So, is there any other method to do this without taking so much time?
  I have tried looking at <code>Pattern matching and replacement in R</code>, but still can't solve the problem.</p>
  
  <p>Thanks in advance. </p>